Skip to main content

ASGI webserver

Project description

Favicorn

CI PyPI version codecov Maintainability Test Coverage

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)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

favicorn-0.0.5-py3-none-any.whl (29.3 kB view details)

Uploaded Python 3

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

Hashes for favicorn-0.0.5.tar.gz
Algorithm Hash digest
SHA256 492438a0eaebe50953dcafde479812ceeb4093a621beb7e2e23af7f69378bd57
MD5 33c7d18de00b89e460bfa1c5a8f8d22d
BLAKE2b-256 9b70fcc3084d66aafef0f9c39843401a80a214073f1136a802073f3ae9a108b7

See more details on using hashes here.

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

Hashes for favicorn-0.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 b639ab068a93e5cd58d72b4f811ab682824a4449739aa7ce558b89e683fac97e
MD5 bcd02fd31ccd7cce4dc699ecd6412342
BLAKE2b-256 a1ed261ce403304cf69088561d32f21fa5761159aba1ad10274e060b308c21fd

See more details on using hashes here.

Supported by

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