What is aioscgi?
aioscgi is a container implementing the Asynchronous Server Gateway Interface
ASGI to serve up asynchronous Web applications
via the Simple Common Gateway Interface protocol. aioscgi supports listening on
TCP or UNIX-domain sockets, as well as using sockets passed in via the systemd
socket-passing protocol. In a systemd environment, when running as a service,
it supports Type=notify.
What is SCGI?
SCGI is a protocol used for communication between HTTP servers and Web applications. Compared to CGI, SCGI is more efficient because it does not fork and execute a separate instance of the application for every request; instead, the application is launched ahead of time and receives multiple requests (either sequentially or concurrently) via socket connections. Compared to FastCGI, SCGI is a much simpler protocol as it uses a separate socket connection for each request, rather than including framing within a single connection to multiplex requests (a feature which is rarely used in FastCGI anyway due to the lack of per-request flow control).
See the Wikipedia and Python SCGI pages for more information.
How do I install it?
aioscgi’s releases are published on PyPI for installation through pip. You can
run pip install aioscgi.
For development, the source is available at GitLab and GitHub.
How do I use it?
aioscgi installs an aioscgi executable. If your ASGI application callable is
named myapp and is in a file called mypackage/mymodule.py, you might run
aioscgi --unix-socket /path/to/socket mypackage.mymodule:myapp. For full
details on available options, run aioscgi --help.
What ASGI protocols does it implement?
aioscgi implements the http and lifespan protocols.
What ASGI extensions does it implement?
environ
aioscgi implements a non-standard extension in the http scope named
environ. scope["extensions"]["environ"] is a dictionary with str keys and
bytes values containing the entire CGI environment, exactly as sent by the
SCGI client. This can be used to extract values that the ASGI specification
does not provide a home for.
http.response.pathsend
aioscgi implements the HTTP Path Send
extension
using the X-Sendfile header. Because it is not possible to automatically
detect whether a given HTTP server understands that header or not, support is
disabled by default and must be enabled with a command-line option.
How does it connect to the rest of my system?
Listening
aioscgi can listen on one or more TCP or UNIX-domain sockets. It can also use listening TCP or UNIX-domain sockets given to it via systemd socket passing. It can listen on multiple sockets, including sockets of different domains and/or a mixture of created sockets and passed sockets, at the same time.
Startup notification
aioscgi supports the systemd service status notification protocol and therefore can be
invoked as a service with Type=notify. It reports startup complete (READY=1) after
the application’s lifespan protocol startup process (if any) is complete and any
listening sockets created by aioscgi itself have been created. It reports shutdown in
progress (STOPPING=1) as soon as it is instructed to begin shutting down.
Control
On a UNIX system, aioscgi handles three signals:
- When aioscgi receives
SIGINT, it immediately stops accepting new connections on any listening socket. It then waits for all existing tasks that were spawned to handle client connections to end naturally before performing lifespan protocol shutdown and terminating. FurtherSIGINTs after the first are ignored. - When aioscgi receives
SIGTERM, it behaves exactly the same asSIGINT. - When aioscgi receives
SIGQUIT, it does everything described forSIGINT, except that it also raises a cancellation exception in every task that was spawned to handle a client connection with the intention of making them stop faster.SIGQUITcan also be sent afterSIGINTorSIGTERM, in which case the cancellation exception is raised in any still-running client-connection-handling tasks. FurtherSIGQUITs after the first are ignored. Even thoughSIGQUITcancels client-connection-handling tasks, the application’s lifespan protocol task (if any) is not cancelled and the normal lifespan shutdown process still occurs.
How do I configure my HTTP server?
Apache
I have not figured out how to get Apache to reliably set the split between
SCRIPT_NAME and PATH_INFO where it’s supposed to be, i.e. at the mount
point of the application. Therefore, passing --base-uri to aioscgi is
necessary.
You should almost certainly not set AllowEncodedSlashes NoDecode when using
aioscgi. If you do this, a request like https://mydomain/myapp/foo%2Fbar will
put /foo%2Fbar in PATH_INFO, which will in turn put /myapp/foo%2Fbar in
scope["path"], in violation of the ASGI specification which says that
scope["path"] must be URL-decoded. Instead, if you need this kind of thing,
set AllowEncodedSlashes On. Then scope["path"] will be /myapp/foo/bar, in
compliance with the ASGI specification, and your application can look at
scope["raw_path"] to get /myapp/foo%2Fbar.
You can set up mod_proxy_scgi to handle requests in two ways, both of which can use either TCP or UNIX-domain sockets to talk to aioscgi:
# Option 1: SetHandler and UNIX-domain sockets
<Proxy "unix:/path/to/socket|scgi://mydomain/myapp/">
</Proxy>
<Location "/myapp/">
SetHandler "proxy:unix:/path/to/socket|scgi://mydomain/myapp/"
</Location>
# Option 2: SetHandler and TCP sockets
<Proxy "scgi://myscgiserver:1234/myapp/">
</Proxy>
<Location "/myapp/">
SetHandler "scgi://myscgiserver:1234/myapp/"
</Location>
# Option 3: ProxyPass and UNIX-domain sockets
ProxyPass /myapp/ unix:/path/to/socket|scgi://mydomain/myapp/
# Option 4: ProxyPass and TCP sockets
ProxyPass /myapp/ scgi://myscgiserver:1234/myapp/
Lighttpd
Lighttpd splits SCRIPT_NAME and PATH_INFO just fine, so there’s no need to
pass --base-uri to aioscgi.
scgi.server = (
# The /myapp/ here defines SCRIPT_NAME as well as mapping the SCGI
# application into the URL space.
"/myapp/" => ("myapp" => (
# Include the next line for UNIX-domain sockets.
"socket" => "/path/to/socket",
# Include the next two lines for TCP sockets.
"host" => "myscgiserver",
"port" => 1234,
"check-local" => 0,
)),
)
Metadata
Release files for aioscgi 2.5.0
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 |
|---|---|---|---|---|
| aioscgi-2.5.0.tar.gz | 30.9 kB | Without provenance | Details for aioscgi-2.5.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| aioscgi-2.5.0-py3-none-any.whl | Python 3 | none | any | Details for aioscgi-2.5.0-py3-none-any.whl |
Total release size: 58.7 kB
Release files / aioscgi-2.5.0.tar.gz
| Download URL | aioscgi-2.5.0.tar.gz |
|---|---|
| Size | 30.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
309aa9ebe653fdce2a65f233370220942e2eca9298b05d0aa89cf3e31aaf558f
|
|
BLAKE2b-256 checksum How to use checksums |
fa2595337f0a81b88f37cb548cab4e1a1f42d5744529d790489cdf7f5d52b5ed
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.12.24 {"installer":{"name":"uv","version":"0.12.24","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / aioscgi-2.5.0-py3-none-any.whl
| Download URL | aioscgi-2.5.0-py3-none-any.whl |
|---|---|
| Size | 27.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
99344f7e1627f99182f4717b71c7ef0fd9c1ea857c17aa887d535452cd3b41f5
|
|
BLAKE2b-256 checksum How to use checksums |
9534f2702ddab7b3dc8d09c4966a3c09305ae459296020d7bf79bbe28887e4fd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.12.24 {"installer":{"name":"uv","version":"0.12.24","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Security for aioscgi 2.5.0
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.