ASGI webserver
Project description
Favicorn
Installation
pip3 install favicorn
ASGI Usage
pip3 install httptools
main.py
import asyncio
import logging
from favicorn import ASGIFavicornBuilder
logging.basicConfig(
level=logging.INFO, format="[%(asctime)s][%(levelname)s] %(message)s"
)
async def app(scope, receive, send) -> None:
await send(
{
"type": "http.response.start",
"status": 200,
"headers": [(b"Content-Length", b"0")],
}
)
await send({"type": "http.response.body", "body": b"", "more_body": False})
s = ASGIFavicornBuilder(
app=app,
http_parser_impl="httptools",
).build()
async def main() -> None:
await s.init()
try:
await s.serve_forever()
finally:
await s.close()
asyncio.run(main())
python3 main.py
[2023-07-14 12:37:14,979][INFO] Socket ('127.0.0.1', 8000) acquired successfully using <class 'favicorn.socket_providers.inet.InetSocketProvider'>
[2023-07-14 12:37:14,979][INFO] Serve forever...
ASGI Usage with websockets
pip3 install httptools wsproto
main.py
import asyncio
import logging
from favicorn import ASGIFavicornBuilder
logging.basicConfig(
level=logging.INFO, format="[%(asctime)s][%(levelname)s] %(message)s"
)
async def app(scope, receive, send) -> None:
await send({"type": "websocket.accept"})
msg = await receive()
await send({"type": "websocket.send", "bytes": b"Something", "text": None})
await send({"type": "websocket.close", "code": 1000})
s = ASGIFavicornBuilder(
app=app,
http_parser_impl="httptools",
ws_impl='wsproto'
).build()
async def main() -> None:
await s.init()
try:
await s.serve_forever()
finally:
await s.close()
asyncio.run(main())
python3 main.py
[2023-07-14 12:37:14,979][INFO] Socket ('127.0.0.1', 8000) acquired successfully using <class 'favicorn.socket_providers.inet.InetSocketProvider'>
[2023-07-14 12:37:14,979][INFO] Serve forever...
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
favicorn-0.0.5.tar.gz
(16.7 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
favicorn-0.0.5-py3-none-any.whl
(29.3 kB
view details)
File details
Details for the file favicorn-0.0.5.tar.gz.
File metadata
- Download URL: favicorn-0.0.5.tar.gz
- Upload date:
- Size: 16.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.17
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
492438a0eaebe50953dcafde479812ceeb4093a621beb7e2e23af7f69378bd57
|
|
| MD5 |
33c7d18de00b89e460bfa1c5a8f8d22d
|
|
| BLAKE2b-256 |
9b70fcc3084d66aafef0f9c39843401a80a214073f1136a802073f3ae9a108b7
|
File details
Details for the file favicorn-0.0.5-py3-none-any.whl.
File metadata
- Download URL: favicorn-0.0.5-py3-none-any.whl
- Upload date:
- Size: 29.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.17
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b639ab068a93e5cd58d72b4f811ab682824a4449739aa7ce558b89e683fac97e
|
|
| MD5 |
bcd02fd31ccd7cce4dc699ecd6412342
|
|
| BLAKE2b-256 |
a1ed261ce403304cf69088561d32f21fa5761159aba1ad10274e060b308c21fd
|