Skip to main content

ASGI web server for FastAPI applications

Project description

Python License

Features

  • Fast Performance - Built on asyncio for high performance
  • ASGI Compatible - Full ASGI interface support for FastAPI
  • Production Ready - Rate limiting, request validation, slowloris protection
  • Multi-Worker - Support for multiple worker processes
  • Auto-Reload - Development mode with file watching
  • Clean Logging - Beautiful uvicorn-style console output
  • Security - Header validation, body size limits, IP rate limiting

Installation

pip install ncorn

Quick Start

ncorn example_app:app

With custom host and port:

ncorn example_app:app --host 0.0.0.0 --port 8080

Multiple workers:

ncorn example_app:app --workers 4

Auto-reload on file changes:

ncorn example_app:app --reload

Configuration

Create a config file:

ncorn config

This creates ncorn.cnf with default settings. You can edit this file and ncorn will use these settings by default.

Example configuration:

{
    "host": "127.0.0.1",
    "port": 8000,
    "workers": 1,
    "reload": false,
    "max_body_size": 16777216,
    "header_timeout": 30.0,
    "rate_limit_requests": 100,
    "rate_limit_window": 60.0
}

Command line options override config file settings.

CLI Options

Option Description Default
app Application in format module:app Required
--host Host to bind to 127.0.0.1
--port Port to bind to 8000
--workers Number of worker processes 1
--reload Enable auto-reload on file changes false
--max-body-size Maximum request body size in bytes 16777216
--header-timeout Header read timeout in seconds 30.0
--rate-limit Rate limit requests per window 100
--rate-limit-window Rate limit window in seconds 60.0
--verbose Enable verbose logging false

Example FastAPI App

from fastapi import FastAPI, HTTPException
from pydantic import BaseModel

app = FastAPI(title="Example App")

class Item(BaseModel):
    name: str
    price: float
    tax: float | None = None

@app.get("/")
async def root():
    return {"message": "Hello from ncorn!"}

@app.get("/health")
async def health():
    return {"status": "healthy"}

@app.post("/items")
async def create_item(item: Item):
    total = item.price + (item.tax or 0)
    return {"name": item.name, "total": total}

Run it:

ncorn example_app:app

Security Features

  • Max Body Size - Limits request body to prevent DoS attacks
  • Header Validation - Validates HTTP headers and rejects invalid requests
  • Slowloris Protection - Timeout for header and body reads
  • IP Rate Limiting - Limits requests per IP address

Architecture

ncorn/
├── __init__.py       # Package init
├── main.py           # Entry point
├── cli.py            # CLI interface
├── server.py         # TCP server
├── protocol.py       # HTTP parser
├── asgi.py           # ASGI adapter
├── config.py         # Configuration
├── logging.py        # Logging
├── reload.py         # Auto-reload
└── middleware/
    ├── base.py       # Middleware base
    ├── validation.py # Request validation
    └── ratelimit.py  # Rate limiting

License

MIT License - see 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

ncorn-1.0.0.tar.gz (20.8 kB view details)

Uploaded Source

Built Distribution

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

ncorn-1.0.0-py3-none-any.whl (25.8 kB view details)

Uploaded Python 3

File details

Details for the file ncorn-1.0.0.tar.gz.

File metadata

  • Download URL: ncorn-1.0.0.tar.gz
  • Upload date:
  • Size: 20.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for ncorn-1.0.0.tar.gz
Algorithm Hash digest
SHA256 d61c40cd61fff068c07967d4fcc1da2af5c577ec2300ab5ad2e675423b793e1f
MD5 7365dd5d655b0a972e66e7c5a1b40597
BLAKE2b-256 60dd145aae309ea61b96a1a4879d7daaff307f06838b4699a80f8050e67744b4

See more details on using hashes here.

File details

Details for the file ncorn-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: ncorn-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 25.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for ncorn-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ceaf29a13dc74f4c20eaa74389e79b9d7a76fb1ee396dd61f307ba7526a155db
MD5 fc7b15f541865828af323ea357b8290f
BLAKE2b-256 4db6f2db10fb634e3dc342d36215f539ab63ad328516e3a1a4839895db65051a

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