-
Notifications
You must be signed in to change notification settings - Fork 1
Documentation
Version: alpha-0.2.2
- swapy
- swapy.wrappers
- swapy.middlewares
- swapy.testing
- swapy._utils (Internal use)
Returns the built app
A short function for all other setting functions like: include, ssl, error, favicon etc. It also handles the entry 'environment' key which can contains 'production' and 'development' or just global variables. The variables can used by extensions. 'production' and 'development' are reserved variables in this case which you can't use if you don't want to separate that.
Parameter | Type | Desctiption |
cfg | dict | The config dict |
Sets the given data as environment
The keys "production" and "development" are reserved. All keys in "production" are used if the app runs without the debug=True. I the other case "development" is used.
Example:
'production': {
'host': '0.0.0.0'
},
'development': {
'host': '127.0.0.1'
}
If the app starts without debug mode the "host" key with the value "0.0.0.0" is the priority value.
Parameter | Type | Desctiption |
data | dict |
Registers a function as error handler.
Parameter | Type | Desctiption |
f | function | Function should receive an Exception object as parameter |
Registers a route to the favicon.
Parameter | Type | Desctiption |
path | str | Path to the file |
file(path, name=None) -> FileWrapper
Ref
Returns a file response.
Parameter | Type | Desctiption |
path | str | Path to the file |
name (optional) | str | Name of the file which will be returned. If it is None the name is like the real file name. |
Returns the value of the give key in environment variables.
Parameter | Type | Desctiption |
key | str |
Includes a source module into the target module.
Parameter | Type | Desctiption |
module | module | The source module |
prefix (optional) | str | Routes from the source module will get the prefix in front of their route |
Registers a function as 404 error handler.
Parameter | Type | Desctiption |
f | function | Functionshould receive an Exception object as parameter |
Route registerer for all http methods.
Parameter | Type | Desctiption |
url (optional) | str | |
methods (optional) | list | tuple | HTTP method |
Route registerer for DELETE http method.
Parameter | Type | Desctiption |
url (optional) | str |
Route registerer for GET http method.
Parameter | Type | Desctiption |
url (optional) | str |
Route registerer for POST http method.
Parameter | Type | Desctiption |
url (optional) | str |
Route registerer for PUT http method.
Parameter | Type | Desctiption |
url (optional) | str |
redirect(location, code=301) -> Response
Ref
Returns a redirect response.
Parameter | Type | Desctiption |
location | str | Url where the user should be redirect |
code | int | HTTP status code which the server returns to the client. It should be any 3xx code. See more at Wikipedia - Http Status Codes. |
Returns a rendered HTML file.
Parameter | Type | Desctiption |
file_apth | str | Path to file including filename and extension |
kwargs | object | Additional arguments which will forward to the template |
Returns a list of all registered routes
Runs the app.
Parameter | Type | Desctiption |
host (optional) | str | IP Address where the server serves. '0.0.0.0' for public address. |
port (optional) | int | Additional arguments which will forward to the template |
debug (optional) | bool | Enables debug output and hot reload |
module_name (optional) | str | Starts the app from the specific module if given |
Sets a value for a key in the global environment
Parameter | Type | Desctiption |
key | str | |
value | object |
Registers a directory as shared.
Parameter | Type | Desctiption |
directory | str | Path to the directory |
Registers SSL.
Parameter | Type | Desctiption |
host | str | IP address of the server |
path | str | Path to the certificates. If it is None swapy generates certificates for development, but then you should have python OpenSSL installed. |
Registers middlewares for global use.
Parameter | Type | Desctiption |
middlewares_ | function[] | Arguments of middlewares (decorators) |
class Request(BaseRequest)
Ref
Request class which inherits from werkzeug's request class. It adds the json function.
Attribute | Type | Desctiption |
session | Session | |
state | State | |
url_args | dict | |
json | dict | Returns dict from json string if available |
secure_cookie | SecureCookie | Returns the secure cookie object from werkzeug |
get_secure_cookie() -> SecureCookie
Ref
Returns the secure cookie object from werkzeug.
Example: res = Response('content', 200, {'my_header': 'value'})
Attribute | Type | Desctiption |
content | str | FileWrapper | |
code | int | |
headers | dict | |
cookies | dict | Setter and getter property for cookies |
Parameter | Type | Desctiption |
content | str | |
code | int (optional) | |
headers | dict (optional) |
Adds cookies to the current
Parameter | Type | Desctiption |
data | dict |
Returns all set cookies.
response_from(args) -> Response
Ref
Casts a result from a route function into a response object
Parameter | Type | Desctiption |
args | list, tuple | Response |
Attribute | Type | Desctiption |
JsonException | function | Alias for json_exception |
DefaultException | function | Alias for default_exception |
JsonMiddleware | function | Alias for json_middleware |
HtmlMiddleware | function | Alias for html_middleware |
CorsMiddleware | function | Alias for cors_middleware |
ExpectKeysMiddleware | function | Alias for expect_keys_middleware |
Exception middleware which returns the error as JSON string.
-> {"message": error, "status_code": code}
Parameter | Type | Desctiption |
error | Exception | The exception object |
Default exception middleware.
Parameter | Type | Desctiption |
error | Exception | The exception object |
Returns every output from an route which has the JSON middleware to a JSON string.
Parameter | Type | Desctiption |
f | function |
Appends a 'text/html' Content-Type header to each response from a route.
Parameter | Type | Desctiption |
f | function |
Appends CORS headers to each response from a route.
Parameter | Type | Desctiption |
f | function |
Returns a 400 error to the client if the route function tries to get a key from an object and cause a KeyError.
Parameter | Type | Desctiption |
f | function |
client(app) -> Client
Ref
Returns the werkzeug Client class with the Response class
Parameter | Type | Desctiption |
app | function | The application function |
Environment class. I need it that it can be referenced.
Attribute | Type | Desctiption |
data | dict | |
development | dict | |
production | dict | |
runtime_data | dict | Returns the whole data |
Parameter | Type | Desctiption |
_state | State | |
data | dict | |
development (optional) | dict | |
production (optional) | dict |
Returns the whole data.
Sets a value for the given key in this environment.
Parameter | Type | Desctiption |
key | str | |
value | object |
Returns the value by the given key.
Example: environment['my_item']
Parameter | Type | Desctiption |
key | str |
Parses the environment dict data into this class.
Parameter | Type | Desctiption |
data | dict |
Sets a value for the given key in this environment.
Parameter | Type | Desctiption |
key | str | |
value | object | |
runtime | str (optional) | Should be 'development' or 'production' |
State for every module.
Attribute | Type | Desctiption |
url_map | Map | |
middlewares | list | |
on_error | function | |
on_not_found | function | |
routes | dict | Contains all registered routes. Example: {'uuid': {'function': function, 'on_error': function, 'url': str}}
|
ssl | str | tuple(str, str) | |
shared | str | |
environment | Environment | |
debug | bool |
Returns the built app.
Parameter | Type | Desctiption |
module | str | Name of the module |
Returns the name of the module which calls swapy.
caller_frame() -> Frame
Ref
Returns the frame of the module which calls swapy.
Sets the environment data to the given module.
Parameter | Type | Desctiption |
module | str | Name of the module |
data | dict |
Sets the given function to the given module as error handler.
Parameter | Type | Desctiption |
module | str | Name of the module |
f | function | The function which will be set for the module as error handler |
Handles the errors at requests.
Parameter | Type | Desctiption |
e | Exception | |
module | str | Name of the module |
Registers route for favicon.
Parameter | Type | Desctiption |
module | str | Name of the module |
path | str | Path to favicon file |
find_route(name) -> Rule | None
Ref
Returns the route by name (url).
Parameter | Type | Desctiption |
name | str | URL of the route |
Includes all functions from source module into the target module.
Parameter | Type | Desctiption |
module | str | Name of the source module |
target | str | Name of the target module |
prefix | str (optional) | Route prefix for functions of the source module |
Adds a state object for every module into the modules list.
Parameter | Type | Desctiption |
module | str | The name of the module which should be initialized |
Registers "not found" function for the 404 error.
Parameter | Type | Desctiption |
module | str | Name of the module |
f | function | Function which will be registered |
Error handler if the route is not found and returns a werkzeug Response object or an exception object.
Parameter | Type | Desctiption |
e | Exception | |
module | str | Name of the module |
Adds a route to the module which calls this and returns the decorator which registers a function.
Parameter | Type | Desctiption |
module | str | name of the module |
url (optional) | str | |
methods (optional) | list | tuple | HTTP methods as strings |
Adds a directory as shared for the given module.
Parameter | Type | Desctiption |
frame | Frame | Frame of the module |
directory | str | Absolute path or relative path |
Adds SSL support for development.
Parameter | Type | Desctiption |
module | str | Name of the module |
host (optional) | str | Domain or IP of the server |
path (optional) | str | Path to cert files (without .crt and .key ending). If empty you have to install python OpenSSL lib. |
state(module) -> State
Ref
Returns state of the given module.
Parameter | Type | Desctiption |
module | str | Name of the module |
Registers middlewares.
Parameter | Type | Desctiption |
module | str | Name of the module |
middlewares_ | list | List of decorators / middlewares (functions) |