Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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: 1 day 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 (about 1 year ago)
- Last Synced: 2024-11-03T20:26:11.815Z (about 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 ✨
[![pypi](https://img.shields.io/pypi/v/asgi-cgi-handler.svg)](https://pypi.org/project/asgi-cgi-handler/)
![python](https://img.shields.io/pypi/pyversions/asgi-cgi-handler)
![implementation](https://img.shields.io/pypi/implementation/asgi-cgi-handler)
![wheel](https://img.shields.io/pypi/wheel/asgi-cgi-handler)
![license](https://img.shields.io/github/license/synodriver/asgi-cgi-handler.svg)
![action](https://img.shields.io/github/workflow/status/synodriver/asgi-cgi-handler/build%20wheel)- 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: ...
```