Datasette plugin for configuring arbitrary ASGI middleware
Project description
datasette-configure-asgi
Datasette plugin for configuring arbitrary ASGI middleware
Installation
pip install datasette-configure-asgi
Usage
This plugin only takes effect if your metadata.json
file contains relevant top-level plugin configuration in a "datasette-configure-asgi"
configuration key.
For example, to wrap your Datasette instance in the asgi-log-to-sqlite
middleware configured to write logs to /tmp/log.db
you would use the following:
{
"plugins": {
"datasette-configure-asgi": [
{
"class": "asgi_log_to_sqlite.AsgiLogToSqlite",
"args": {
"file": "/tmp/log.db"
}
}
]
}
}
The "datasette-configure-asgi"
key should be a list of JSON objects. Each object should have a "class"
key indicating the class to be used, and an optional "args"
key providing any necessary arguments to be passed to that class constructor.
Plugin structure
This plugin can be used to wrap your Datasette instance in any ASGI middleware that conforms to the following structure:
class SomeAsgiMiddleware:
def __init__(self, app, arg1, arg2):
self.app = app
self.arg1 = arg1
self.arg2 = arg2
async def __call__(self, scope, receive, send):
start = time.time()
await self.app(scope, receive, send)
end = time.time()
print("Time taken: {}".format(end - start))
So the middleware is a class with a constructor which takes the wrapped application as a first argument, app
, followed by further named arguments to configure the middleware. It provides an async def __call__(self, scope, receive, send)
method to implement the middleware's behavior.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
File details
Details for the file datasette_configure_asgi-0.1-py3-none-any.whl
.
File metadata
- Download URL: datasette_configure_asgi-0.1-py3-none-any.whl
- Upload date:
- Size: 7.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.40.2 CPython/3.6.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2061cf5184f5d9aaa7909f6fef54702c2595fcc731bdd4472518c07ce3fa8cb2 |
|
MD5 | 79b55380adfb541b4c33cf952eb9264e |
|
BLAKE2b-256 | f776c2ae1907ff0c5e8f3366c2041c1d73019b7825d6948ce880eb3ddf60be20 |