ASGI web server for FastAPI applications
Project description
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.json 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,
"max_header_size": 8192,
"max_headers_total_size": 65536,
"header_timeout": 30.0,
"body_timeout": 60.0,
"request_timeout": 10.0,
"response_timeout": 10.0,
"keepalive_timeout": 5.0,
"keepalive_requests": 100,
"max_headers": 100,
"max_connections": 1000,
"max_connections_per_ip": 50,
"rate_limit_requests": 100,
"rate_limit_window": 60.0,
"write_buffer_limit": 65536,
"drain_timeout": 1.0,
"ip_whitelist": [],
"ip_blacklist": [],
"enable_security_headers": true,
"waf_max_query_length": 4096
}
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
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
File details
Details for the file ncorn-1.0.2.tar.gz.
File metadata
- Download URL: ncorn-1.0.2.tar.gz
- Upload date:
- Size: 21.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
332ad7e68b880d2062f89734a4c23d70f55ec36725ed49315b7326cbd0e9d0d8
|
|
| MD5 |
5f73f11badc887d6d59cda4197901931
|
|
| BLAKE2b-256 |
ff35dd87f58da7f875d970945f592426285eb11bae4a9b1af55a66540282c4a7
|
File details
Details for the file ncorn-1.0.2-py3-none-any.whl.
File metadata
- Download URL: ncorn-1.0.2-py3-none-any.whl
- Upload date:
- Size: 26.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
25f7c685cb6e730f1f0680c3576250fe953cf707ec1177f268d7b0a15da8376f
|
|
| MD5 |
62fd24a39b2d542f08cbb00debec7b78
|
|
| BLAKE2b-256 |
749f1493d5e9a63f9917cb37e178cac6b0960c74c815559fb2952169f758ff51
|