Skip to main content

A sans-I/O implementation of the SCGI specification.

Project description

What is sioscgi?

sioscgi is an implementation of the Simple Common Gateway Interface (SCGI) protocol under the Sans-I/O philosophy.

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.

What is Sans-I/O?

Sans-I/O is a philosophy for developing protocol processing libraries in which the library does not do any I/O. Instead, a user of the library is responsible for transferring blocks of bytes between the socket or pipe and the protocol library, and for receiving application-level protocol items from and sending them to the library. This obviously makes a sans-I/O library a little more difficult to use, but comes with the advantage that the same library can be used with any I/O and concurrency mechanism: the same library should be usable in a single-request-at-a-time server, a process-per-request or thread-per-request blocking server, a server using select/poll and continuations, or a server using asyncio, Twisted, or any other asynchronous framework.

See SansIO for more information.

How do I install it?

sioscgi’s releases are published on PyPI for installation through pip. You can run pip install sioscgi.

For development, the source is available at GitLab and GitHub.

How do I use it?

In general terms, as follows:

  1. Accept an SCGI connection from the HTTP server (or other SCGI client).

  2. Construct an SCGIConnection object.

  3. Receive the request from the SCGI client by repeating the following until a RequestEnd event occurs:

    1. Read some bytes from the connection and pass them to SCGIConnection.receive_data.

    2. Call SCGIConnection.next_event to receive high-level events corresponding to the received data (one RequestHeaders, zero or more RequestBody events, and one RequestEnd).

  4. Send the response to the SCGI client using SCGIConnection.send, sending first a ResponseHeaders event, then zero or more ResponseBody events, then a ResponseEnd event, and sending the returned bytes over the connection.

This being a sans-I/O library, how exactly you implement each step will depend on what I/O and application framework you’re working under. For example, for a thread-per-request or process-per-request server, you would likely do a blocking receive from a normal function in step 3.1; in an asyncio-based server you would instead await new data from a coroutine.

For detailed information about the classes and methods available, see the module documentation provided in the docstrings by running import sioscgi followed by help(sioscgi).

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sioscgi-4.0.0.tar.gz (25.9 kB view details)

Uploaded Source

Built Distribution

sioscgi-4.0.0-py3-none-any.whl (21.1 kB view details)

Uploaded Python 3

File details

Details for the file sioscgi-4.0.0.tar.gz.

File metadata

  • Download URL: sioscgi-4.0.0.tar.gz
  • Upload date:
  • Size: 25.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.11

File hashes

Hashes for sioscgi-4.0.0.tar.gz
Algorithm Hash digest
SHA256 4b8f51468c67737d03a24e8a421382b362fa00830b474d7b6b0dbf4c2efc98a7
MD5 2456bdef8039a8b79bb2dc69ee6cbd52
BLAKE2b-256 22f960b7e150660fa8c4cacf16af29ee0ef4bde6e14b5f9a1a52047ae0690688

See more details on using hashes here.

File details

Details for the file sioscgi-4.0.0-py3-none-any.whl.

File metadata

  • Download URL: sioscgi-4.0.0-py3-none-any.whl
  • Upload date:
  • Size: 21.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.11

File hashes

Hashes for sioscgi-4.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 56822ba699b013fc39f25d0f20c2e94412d8b3ba608c59a8b18b840b61fd2f9b
MD5 8117daa261e14b7ee8afea44e1f6ae30
BLAKE2b-256 40de6f0079da26c86541d6191b88dd7c9eae58579b6a4235e783b262ee782f03

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page