Aeros

Package Contents

Classes

Quart

The web framework class, handles requests and returns responses.

Compression

WebServer

This is the main server class which extends a standard Flask class by a bunch of features and major

EasyRequest

A helper class that make request handling easier

AdvancedThread

This thread class extends the pure-python “Thread” class

Compression

SimpleCache

This class is used to control the cache objects.

FilesystemCache

This class is used to control the cache objects.

RedisCache

This class is used to control the cache objects.

Functions

make_config_from_hypercorn_args(hypercorn_string: str, config: Config = Config()) → Config

Overrides a given config’s items if they are specified in the hypercorn args string

class Aeros.Quart(import_name: str, static_url_path: Optional[str] = None, static_folder: Optional[str] = 'static', static_host: Optional[str] = None, host_matching: bool = False, subdomain_matching: bool = False, template_folder: Optional[str] = 'templates', root_path: Optional[str] = None, instance_path: Optional[str] = None, instance_relative_config: bool = False)[source]

Bases: quart.Quart

The web framework class, handles requests and returns responses.

The primary method from a serving viewpoint is handle_request(), from an application viewpoint all the other methods are vital.

This can be extended in many ways, with most methods designed with this in mind. Additionally any of the classes listed as attributes can be replaced.

app_ctx_globals_class

The class to use for the g object

asgi_http_class

The class to use to handle the ASGI HTTP protocol.

asgi_lifespan_class

The class to use to handle the ASGI lifespan protocol.

asgi_websocket_class

The class to use to handle the ASGI websocket protocol.

config_class

The class to use for the configuration.

env

The name of the environment the app is running on.

debug

Wrapper around configuration DEBUG value, in many places this will result in more output if True. If unset, debug mode will be activated if environ is set to ‘development’.

jinja_environment

The class to use for the jinja environment.

jinja_options

The default options to set when creating the jinja environment.

json_decoder

The decoder for JSON data.

json_encoder

The encoder for JSON data.

permanent_session_lifetime

Wrapper around configuration PERMANENT_SESSION_LIFETIME value. Specifies how long the session data should survive.

request_class

The class to use for requests.

response_class

The class to user for responses.

secret_key

Warpper around configuration SECRET_KEY value. The app secret for signing sessions.

Wrapper around configuration SESSION_COOKIE_NAME, use to specify the cookie name for session data.

session_interface

The class to use as the session interface.

url_map_class

The class to map rules to endpoints.

url_rule_class

The class to use for URL rules.

websocket_class

The class to use for websockets.

asgi_http_class
class Aeros.Compression(level: int = 2, min_size: int = 500, mimetypes: List = None)[source]
init_app(self, app: Quart)[source]
Aeros.make_config_from_hypercorn_args(hypercorn_string: str, config: Config = Config()) → Config[source]

Overrides a given config’s items if they are specified in the hypercorn args string

class Aeros.WebServer(import_name: str, host: str = '0.0.0.0', port: int = 80, include_server_header: bool = True, hypercorn_arg_string: str = '', worker_threads: int = 1, logging_level: Union[int, str] = 'INFO', cache: Cache = Cache(), compression: Compression = Compression(level=2, min_size=10), global_headers: Dict[str, str] = None, *args, **kwargs)[source]

Bases: Aeros.patches.quart.app.Quart

This is the main server class which extends a standard Flask class by a bunch of features and major performance improvements. It extends the Quart class, which by itself is already an enhanced version of the Flask class. This class however allows production-grade deployment using the hypercorn WSGI server as production server. But instead of calling the hypercorn command via the console, it can be started directly from the Python code itself, making it easier to integrate in higher-level scripts and applications without calling os.system() od subprocess.Popen().

_get_own_instance_path(self)[source]

Retrieves the file and variable name of this instance to be used in the Hypercorn CLI.

Since hypercorn needs the application’s file and global variable name, an instance needs to know it’s own origin file and name. But since this class is not defined in the same file as it is called or defined from, this method searches for the correct module/file and evaluates it’s instance name.

Warning

Deprecation warning: This method will be removed in future versions. Usage is highly discouraged.

cache(self, timeout=None, key_prefix='view/%s', unless=None, forced_update=None, response_filter=None, query_string=False, hash_method=hashlib.md5, cache_none=False)[source]

A simple wrapper that forwards cached() decorator to the internal Cache() instance. May be used as the normal @cache.cached() decorator.

run_server(self) → None[source]

Generates the necessary config and runs the server instance.

class Aeros.EasyRequest[source]

A helper class that make request handling easier

All attributes are assessable via the same syntax, while with Flask.request or quart.request, you will have slightly different syntax when retrieving different request attributes.

Hint

You only need to await attributes that need calculation, for example evaluating the request body, like .json or .form.

headers = EasyRequest.headers
params = EasyRequest.params
form = await EasyRequest.form # requires time for calculation
json = await EasyRequest.json # requires time for calculation
params :dict

The URL parameters like Flask.request.params.

headers :dict

The request headers like Flask.request.headers.

__quart_request :request

The Flask.request. instance that is used in the current scope.

__load(self)

loads the content of Flask.request into this instance and returns it.

__call__(self, f)[source]

Decorates an endpoint function to use the EasyRequest with.

async property form(self)

The request form data like Flask.request.form.

async property json(self)

The request body data (as JSON) like Flask.request.form.

Be aware that in order for Flask.request.get_json() to return a JSON dictionary, the Content-Type header must be set to application/json.

class Aeros.AdvancedThread(*args, **kwargs)[source]

Bases: threading.Thread

This thread class extends the pure-python “Thread” class by a stop() function to terminate the thread’s run() method.

__get_id(self)

Get’s the threads PID.

stop(self)[source]

Sends a kill signal to the given thread

class Aeros.Compression(level: int = 2, min_size: int = 500, mimetypes: List = None)[source]
init_app(self, app: Quart)[source]
class Aeros.SimpleCache(*args, **kwargs)[source]

Bases: Aeros.patches.flask_caching.Cache

This class is used to control the cache objects.

class Aeros.FilesystemCache(directory: str, *args, **kwargs)[source]

Bases: Aeros.patches.flask_caching.Cache

This class is used to control the cache objects.

class Aeros.RedisCache(host: str, port: int, password: str = '', db: int = 0, *args, **kwargs)[source]

Bases: Aeros.patches.flask_caching.Cache

This class is used to control the cache objects.