ASGI S3 storage
Project description
asgi-s3
Staticfile management tools and ASGI middleware support for Amazon S3.
Work in Progress: A lot of what is here currently will be changing.
CLI
s3 sync
...todo
Middleware
The middleware is designed to work with any ASGI application. Here is raw ASGI example:
from asgi_s3.middleware import S3StorageMiddleware
async def app(scope, receive, send):
url_for = scope["asgi_s3"]["url_for"]
await send(
{
"type": "http.response.start",
"status": 200,
"headers": [[b"content-type", b"text/html; charset=utf-8"]],
}
)
html_content = f"""
<!DOCTYPE html>
<html>
<head>
<title>ASGI S3 example</title>
<link rel="stylesheet" href="{url_for('style.css')}">
</head>
<body>
Hello, world.
</body>
</html>
"""
await send({"type": "http.response.body", "body": html_content.encode()})
app = S3StorageMiddleware(
app,
bucket_name="my-bucket",
static_dir="path/to/static/files",
)
And here is an example using Starlette:
from starlette.applications import Starlette
from starlette.templating import Jinja2Templates
from asgi_s3.middleware import S3StorageMiddleware
templates = Jinja2Templates("templates")
app = Starlette()
@app.route("/")
def homepage(request):
s3_url_for = request.scope["asgi_s3"]["s3_url_for"]
return templates.TemplateResponse(
"index.html", {"request": request, "s3_url_for": s3_url_for}
)
app.add_middleware(
S3StorageMiddleware,
bucket_name="my-bucket",
static_dir="path/to/static/files",
)
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 Distribution
asgi-s3-0.0.2.tar.gz
(5.8 kB
view details)
File details
Details for the file asgi-s3-0.0.2.tar.gz
.
File metadata
- Download URL: asgi-s3-0.0.2.tar.gz
- Upload date:
- Size: 5.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.6.8rc1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 068339fe0dd0841db1caa3572a44c01b68076780538e79ff79ce492fe0334b74 |
|
MD5 | 9de882a401696a9031c86d5b2586e64f |
|
BLAKE2b-256 | 90200c5155cfb12cc3635a2b600e568d2dcba906437859613d3326fe4d1a9023 |