Skip to main content

Add your description here

Project description

uASGI: A High-Performance ASGI Web Server

uASGI is a lightweight and efficient ASGI (Asynchronous Server Gateway Interface) web server for Python, designed for speed and flexibility. It supports both HTTP/1.1 and HTTP/2 protocols, with built-in SSL/TLS capabilities and a multiprocessing worker model for handling concurrent requests.

Inspired by the need for a simple yet powerful ASGI server, uASGI aims to provide a solid foundation for deploying asynchronous Python web applications.

Features

  • ASGI Specification Compliance: Fully compatible with ASGI 2.0 and 3.0 applications (HTTP and Lifespan).
  • HTTP/1.1 Support: Robust handling of HTTP/1.1 requests using httptools.
  • HTTP/2 Support: Native HTTP/2 (H2) implementation using h2 for improved performance and multiplexing.
  • SSL/TLS: Secure communication with built-in SSL context creation.
  • Multiprocessing Workers: Scale your application across multiple CPU cores with a configurable worker pool.
  • Asynchronous I/O: Built on asyncio and optimized with uvloop for high concurrency.

Installation

uASGI requires Python 3.13 or later.

You can install uASGI and its dependencies using pip or uv

pip install uasgi
uv add uasgi

Usage

Running a Simple ASGI Application

Here's how you can run a basic FastAPI application with uASGI.

First, create an example.py (or similar) file:

import os
from fastapi import FastAPI
from uasgi import run, create_logger
from contextlib import asynccontextmanager

logger = create_logger('app', 'INFO')

@asynccontextmanager
async def lifespan(_):
    logger.info('Application is starting...')
    yield {
        'property': 'value'
    }
    logger.info('Application is shutdown...')


def create_app():
    app = FastAPI(
        lifespan=lifespan,
    )

    @app.get('/')
    async def index():
        return {
            "Hello": "World"
        }

    return app


def main():
    run(
        app_factory=create_app, 
    )


if __name__ == '__main__':
    main()

Then, run it from your terminal:

python example.py

This will start the server on http://127.0.0.1:5000 with HTTP/1.1.

Configuration Options

The run function accepts several parameters to configure the server:

  • app_factory: A callable that returns your ASGI application instance.
  • host (str): The host address to bind to (default: '127.0.0.1').
  • port (int): The port to listen on (default: 5000).
  • backlog (int): The maximum number of pending connections (default: 1024).
  • workers (int, optional): The number of worker processes to spawn. If None, runs in a single process.
  • ssl_cert_file (str, optional): Path to the SSL certificate file.
  • ssl_key_file (str, optional): Path to the SSL key file.
  • enable_h2 (bool): Enable HTTP/2 protocol (default: False). Requires SSL.
  • log_level (str): Set the logging level ('DEBUG', 'INFO', 'WARNING', 'ERROR').

Development

To set up the development environment:

  1. Clone the repository:
    git clone https://github.com/your-username/uasgi.git
    cd uasgi
    
  2. Install dependencies:
    uv sync # or pip install -e .
    

Contributing

Contributions are welcome! Please see the CONTRIBUTING.md (to be created) for guidelines.

License

This project is licensed under the MIT License - see the LICENSE file for details.

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

uasgi-0.1.1b1.tar.gz (12.6 kB view details)

Uploaded Source

Built Distribution

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

uasgi-0.1.1b1-py3-none-any.whl (14.2 kB view details)

Uploaded Python 3

File details

Details for the file uasgi-0.1.1b1.tar.gz.

File metadata

  • Download URL: uasgi-0.1.1b1.tar.gz
  • Upload date:
  • Size: 12.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.21

File hashes

Hashes for uasgi-0.1.1b1.tar.gz
Algorithm Hash digest
SHA256 1b991820f9070e5a0639f95433a7eaab34b97d6276cbca492cd4fdc14ba94af2
MD5 65daa31eb178ea6d8881b431c6d3f555
BLAKE2b-256 64a0e7bc6622deca4bf0cc3d8980cfe05f75dbfbdab0fc94c63561f2cf42e205

See more details on using hashes here.

File details

Details for the file uasgi-0.1.1b1-py3-none-any.whl.

File metadata

  • Download URL: uasgi-0.1.1b1-py3-none-any.whl
  • Upload date:
  • Size: 14.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.21

File hashes

Hashes for uasgi-0.1.1b1-py3-none-any.whl
Algorithm Hash digest
SHA256 974339ca73e45c9777a26b0920ed03f53be7331f0d5c9d24bbb346384d2102e5
MD5 b0f5afd977f8a672c19fc13edaf4e54e
BLAKE2b-256 cf8d9076e61ee4e70d1c2e2462ec0ea48931f52253097b88227a47c9ffc1afe6

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