asgi-s3
Static file management tools and ASGI middleware support for Amazon S3.
Work in Progress: A lot of what is here currently will be changing, not recommended for any serious usage at this point.
Requirements: Python 3.6+
Installation
pip install asgi-s3
...but you probably just want to clone the master branch for the moment.
CLI
s3 create-bucket Create a new S3 bucket.
s3 list-buckets List all S3 buckets.
s3 sync-bucket Sync a bucket with a local static file directory.
...todo
Middleware
The middleware is designed to work with any ASGI application. Here is raw ASGI example:
from asgi_s3.middleware import S3StorageMiddleware, s3_url_for
AWS_ACCESS_KEY_ID = "access-key-id"
AWS_SECRET_ACCESS_KEY = "secret-access-key"
BUCKET_NAME = "my-bucket"
REGION_NAME = "region-name"
STATIC_DIR = "path/to/static/files"
async def app(scope, receive, send):
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="{s3_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=BUCKET_NAME,
static_dir=STATIC_DIR,
region_name=REGION_NAME,
aws_access_key_id=AWS_ACCESS_KEY_ID,
aws_secret_access_key=AWS_SECRET_ACCESS_KEY,
)
And here is an example using Starlette:
from starlette.applications import Starlette
from starlette.templating import Jinja2Templates
from asgi_s3.middleware import S3StorageMiddleware, s3_url_for
templates = Jinja2Templates("templates")
app = Starlette()
@app.route("/")
def homepage(request):
return templates.TemplateResponse(
"index.html", {"request": request, "s3_url_for": s3_url_for}
)
AWS_ACCESS_KEY_ID = "access-key-id"
AWS_SECRET_ACCESS_KEY = "secret-access-key"
BUCKET_NAME = "my-bucket"
REGION_NAME = "region-name"
STATIC_DIR = "path/to/static/files"
app.add_middleware(
S3StorageMiddleware,
bucket_name=BUCKET_NAME,
static_dir=STATIC_DIR,
region_name=REGION_NAME,
aws_access_key_id=AWS_ACCESS_KEY_ID,
aws_secret_access_key=AWS_SECRET_ACCESS_KEY,
)
Metadata
Release files for asgi-s3 0.0.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| asgi-s3-0.0.3.tar.gz | 6.7 kB | Without provenance | Details for asgi-s3-0.0.3.tar.gz |
Release files / asgi-s3-0.0.3.tar.gz
| Download URL | asgi-s3-0.0.3.tar.gz |
|---|---|
| Size | 6.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
fb6c3dbf83136b9f424d63a75ae66218349c2fc217a7e3dcdf73c69931bbf4c3
|
|
BLAKE2b-256 checksum How to use checksums |
c3ddae950e795429cf1b1c2693edbf77400a64387fe8271c02e56ebee18758f8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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
|
Security for asgi-s3 0.0.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.