https://github.com/synodriver/asgi-cgi-handler
run cgi scripts inside asgi, and with websocket, sse support
https://github.com/synodriver/asgi-cgi-handler
asgi cgi websocket
Last synced: 17 days ago
JSON representation
run cgi scripts inside asgi, and with websocket, sse support
- Host: GitHub
- URL: https://github.com/synodriver/asgi-cgi-handler
- Owner: synodriver
- Created: 2022-09-02T15:32:50.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2023-12-09T07:08:10.000Z (over 1 year ago)
- Last Synced: 2025-02-14T00:23:52.729Z (2 months ago)
- Topics: asgi, cgi, websocket
- Language: Python
- Homepage:
- Size: 25.4 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.markdown
Awesome Lists containing this project
README
✨ asgi-cgi-handler ✨
[](https://pypi.org/project/asgi-cgi-handler/)




- run cgi scripts inside an asgi server
- simple usage
```python
import uvicorn
from asgi_cgi import HTTPCGIHandler, WebsocketCGIHandleruvicorn.run(HTTPCGIHandler())
```- A more complex example
```python
from fastapi import FastAPI
from asgi_cgi import HTTPCGIHandler, WebsocketCGIHandler, SSECGIHandlerapp = FastAPI(title="CGI Server")
app.mount("/cgi-bin", HTTPCGIHandler()) # type: ignore
app.mount("/ws", WebsocketCGIHandler()) # type: ignore
app.mount("/sse", SSECGIHandler()) # type: ignore
```As you can see, we have websocket support, which is inspired by
[websocketd](https://github.com/joewalnes/websocketd). Currently, more tests are needed.The ```WebsocketCGIHandler``` route requests to endpoint executables and feed websocket data
into process's stdin and send stdout to client line by line.The ```SSECGIHandler```, means ```server send event```, is just like the websocket one, but it only send stdout to client.
## Apis
```python
ErrHandler = Callable[[bytes], Union[Awaitable[None], None]]class HTTPCGIHandler:
def __init__(self, directory: str=..., error_handler: ErrHandler=...) -> None: ...class WebsocketCGIHandler:
def __init__(self, directory: str=..., error_handler: ErrHandler=...) -> None: ...class SSECGIHandler:
def __init__(self, directory: str=..., error_handler: ErrHandler=...) -> None: ...
```