Aeros
¶
Subpackages¶
Package Contents¶
Classes¶
This is the main server class which extends a standard Flask class by a bunch of features and major |
|
A helper class that makes request handling more uniform. |
|
This thread class extends the pure-python “Thread” class |
|
This class should be used to implement a Gzip compression to your Aeros web server. |
|
This class should be used to implement a Br compression to your Aeros web server. |
|
The most basic cache that requires no set-up and no arguments. |
|
Stores cached responses on the file system, |
|
An alias for FileSystemCache |
|
A Redis client to store responses on an external Redis server. |
|
This class manipulates the Cache-Control header in all responses sent from an endpoint |
|
An enum to replace the cache option strings with variables for auto-complete in most IDEs. |
-
class
Aeros.
WebServer
(import_name: str, host: str = '0.0.0.0', port: int = 80, include_server_header: bool = True, logging_level: int = INFO, cache: Aeros.caching.server.Cache = None, compression: Aeros.compression.Base = None, global_headers: dict = {}, *args, **kwargs)[source]¶ Bases:
quart.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 uvicorn ASGI server as production server. But instead of calling the uvicorn 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() or subprocess.Popen().
-
__log_format_std
= [%(asctime)s] %(levelname)s: %(message)s¶
-
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 the cached() decorator to the internal Cache() instance. May be used as the normal @cache.cached() decorator.
-
clear_cache
(self)¶ Clears the WebServer instance cache. Use with caution!
-
_get_own_instance_path
(self) → str[source]¶ Retrieves the file and variable name of this instance to be used in the uvicorn CLI.
Since uvicorn needs the application’s file and global variable name for multicore execution, 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
This method is a beta feature. Use with caution (good testing).
-
run_server
(self, host: str = None, port: int = None, log_level: int = None, access_log_file: str = None, access_log_to_std: bool = True, traceback: bool = True, soft_limit: int = 32, hard_limit: int = 42, **kwargs) → None[source]¶ Generates the necessary config and runs the server instance. Possible keyword arguments are the same as supported by the uvicorn.run() method as they are passed into Config(app, **kwargs). This method also configures features like caching and compression that are not default in Quart or Flask and unique to Aeros or require third-party modules to be configured.
-
run
(self, *args, **kwargs)¶ Run this application.
This is best used for development only, see Hypercorn for production servers.
- Parameters
host – Hostname to listen on. By default this is loopback only, use 0.0.0.0 to have the server listen externally.
port – Port number to listen on.
debug – If set enable (or disable) debug mode and debug output.
use_reloader – Automatically reload on code changes.
loop – Asyncio loop to create the server in, if None, take default one. If specified it is the caller’s responsibility to close and cleanup the loop.
ca_certs – Path to the SSL CA certificate file.
certfile – Path to the SSL certificate file.
keyfile – Path to the SSL key file.
-
route
(self, *args, **kwargs)¶ Add a route to the application.
This is designed to be used as a decorator, if used to decorate a synchronous function, the function will be wrapped in
run_sync()
and run in a thread executor (with the wrapped function returned). An example usage,@app.route('/') async def route(): ...
- Parameters
rule – The path to route on, should start with a
/
.methods – List of HTTP verbs the function routes.
endpoint – Optional endpoint name, if not present the function name is used.
defaults –
A dictionary of variables to provide automatically, use to provide a simpler default path for a route, e.g. to allow for
/book
rather than/book/0
,@app.route('/book', defaults={'page': 0}) @app.route('/book/<int:page>') def book(page): ...
host – The full host name for this route (should include subdomain if needed) - cannot be used with subdomain.
subdomain – A subdomain for this specific route.
provide_automatic_options – Optionally False to prevent OPTION handling.
strict_slashes – Strictly match the trailing slash present in the path. Will redirect a leaf (no slash) to a branch (with slash).
-
-
class
Aeros.
EasyRequest
[source]¶ A helper class that makes request handling more uniform.
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, which can be very irritating and take much time debugging your code for missing parentheses or an await statement.
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 quart.request.headers.
The request cookies like quart.request.cookies.
-
__quart_request
:request¶ The quart.request. instance that is used in the current scope.
-
__load
(self)¶ Loads the content of quart.request into this instance and returns it.
-
__call__
(self, f)[source]¶ Decorates an endpoint function to use the EasyRequest with, which makes EasyRequest available in that endpoint method.
-
async property
form
(self)¶ The request form data like quart.request.form.
-
async property
json
(self)¶ The request body data (as JSON) like quart.request.form.
Be aware that in order for quart.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.
Warning
The stop feature is still experimental and needs extensive testing.
-
__get_id
(self)¶ Get’s the threads PID.
-
-
class
Aeros.
Gzip
(level: int = 2, min_size: int = 500, mimetypes: List = None)¶ Bases:
Aeros.compression.Base
This class should be used to implement a Gzip compression to your Aeros web server.
-
algorithm
= gzip¶
-
-
class
Aeros.
Br
(level: int = 2, min_size: int = 500, mimetypes: List = None)¶ Bases:
Aeros.compression.Base
This class should be used to implement a Br compression to your Aeros web server.
-
algorithm
= br¶
-
-
class
Aeros.
SimpleCache
(app: Optional[Flask] = None, with_jinja2_ext: bool = True, config=None)[source]¶ Bases:
flask_caching.Cache
The most basic cache that requires no set-up and no arguments.
-
class
Aeros.
FileSystemCache
(app: Optional[Flask] = None, with_jinja2_ext: bool = True, config=None)¶ Bases:
flask_caching.Cache
Stores cached responses on the file system, good for huge caches that don’t fit into memory.
-
class
Aeros.
FilesystemCache
[source]¶ An alias for FileSystemCache
Warning
This class is deprecated! Use FileSystemCache instead.
-
class
Aeros.
RedisCache
(app: Optional[Flask] = None, with_jinja2_ext: bool = True, config=None)[source]¶ Bases:
flask_caching.Cache
A Redis client to store responses on an external Redis server.
-
class
Aeros.
CacheControl
(cache_type: Aeros.caching.client.CacheTypes, max_age: int = None, immutable: bool = False, no_transform: bool = False, stale_while_revalidate: int = None, stale_if_error: bool = False, cache_on_status: list = [200])¶ This class manipulates the Cache-Control header in all responses sent from an endpoint decorated with this class.
Hint
If you need conditional caching rules you may still use response from quart to manipulate the Cache-Control header to your needs.
-
__call__
(self, f: callable) → callable¶
-