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

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

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.

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

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.1.tar.gz (20.2 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.1-py3-none-any.whl (25.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: ncorn-1.0.1.tar.gz
  • Upload date:
  • Size: 20.2 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.1.tar.gz
Algorithm Hash digest
SHA256 5b6e2eb81221396f56f3a2e30ca20bb53b9551c7d00bbfb728e8ec1a618558e9
MD5 a0da915e42f795f936932b52439e08a6
BLAKE2b-256 daf2aa468731e83ff6ba5b89cc03a98a3f5859da0cbc2748c925cc74c04bb2e5

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ncorn-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 25.5 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 8faa00f803c45f047bf07cf650c6548836b005879ff27857747f3a421fce1f2e
MD5 bdf5018f4d7cc56004c71efe28b57111
BLAKE2b-256 81210005b7633c638ef801901b8937dddefde1e18743c0c34969b4e934aee90b

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