Simple ASGI micro framework for Python
This project has been archived.
The maintainers of this project have marked this project as archived. No new releases are expected.
Project description
This project is deprecated, and you need to migrate to AltAPI. this version will not be maintained.
PyPi: https://pypi.org/project/AltAPI
Github: https://github.com/amogus-gggy/AltAPI
Nebula
Simple ASGI micro framework for Python, which supports both HTTP and WebSockets.
Changelog
Version 1.1
- Added caching system (
InMemoryCache,CacheMiddleware,@cachedecorator) - Improved
render_template()andJinja2Templatesintegration - Added automatic static file serving via
static_directoryparameter - Minor improvements for static and templates directory handling
Installation
pip install project-nebula
Usage
from nebula import Nebula
from nebula.http import JSONResponse, HTMLResponse
app = Nebula()
@app.get("/")
async def home(request):
return HTMLResponse("<h1>Welcome to Nebula!</h1>")
@app.get("/api/hello")
async def hello(request):
return JSONResponse({"message": "Hello, World!"})
@app.post("/api/echo")
async def echo(request):
data = await request.json()
return JSONResponse({"echo": data})
# Typed path parameters
@app.get("/api/users/{id:int}")
async def get_user(request):
user_id = request.path_params["id"] # int
return JSONResponse({"id": user_id, "name": f"User {user_id}"})
# Sync handler example
@app.get("/api/sync")
def sync_handler(request):
return JSONResponse({"type": "sync", "message": "I'm synchronous!"})
# Run server directly
if __name__ == "__main__":
app.run(host="0.0.0.0", port=8000)
Run
python examples/app.py
Or with uvicorn directly:
uvicorn examples.app:app --reload
Or using app.run():
python your_app.py
Project Structure
src/nebula/
├── __init__.py # Main package exports
├── app.py # Main Nebula application class
├── router.pyx # Cython router (optimized)
├── http/ # HTTP components
│ ├── __init__.py
│ ├── request.py # Request handling
│ └── responses.py # Response classes
├── websocket/ # WebSocket support
│ ├── __init__.py
│ └── ws.py
├── templating/ # Template rendering (Jinja2)
│ ├── __init__.py
│ ├── templates.py
│ └── default_templates.py
├── caching/ # Caching system
│ ├── __init__.py
│ └── cache.py
└── middleware/ # Middleware support
├── __init__.py
└── middleware.py
Recommended Imports
# Main application
from nebula import Nebula
# HTTP components
from nebula.http import Request, JSONResponse, HTMLResponse, PlainTextResponse, StreamingResponse, FileResponse, RedirectResponse
# WebSocket
from nebula.websocket import WebSocket, WebSocketState
# Templates
from nebula.templating import Jinja2Templates, render_template
# Caching
from nebula.caching import cache, InMemoryCache, CacheMiddleware
# Middleware
from nebula.middleware import Middleware, BaseMiddleware
Features
- ASGI compliant
- JSON and HTML responses
- Typed path parameters (
/users/{id:int},{name:str},{value:float}) - Request body parsing (JSON, text)
- Multiple HTTP methods (GET, POST, PUT, DELETE)
- Sync and async handlers
- Full WebSocket support
- Optimized Cython router
- Static file mounting (automatic via
static_directory) - Template rendering (Jinja2)
- Multiple response types (PlainText, Streaming, File, Redirect)
- Built-in caching with
InMemoryCache - Built-in server (
app.run())
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
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 project_nebula-1.1.1.tar.gz.
File metadata
- Download URL: project_nebula-1.1.1.tar.gz
- Upload date:
- Size: 121.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f32337253f20cc7e4467e3988632936ebb8b8f3b91f2441ad32679c3b1323f5f
|
|
| MD5 |
7cf6193874c0198199bb009cebd61527
|
|
| BLAKE2b-256 |
f1419e28fd92c19f6dc19a5b6d2c66b13862ea6e9e638e5ed33f8b24a04cb234
|
File details
Details for the file project_nebula-1.1.1-cp312-cp312-win_amd64.whl.
File metadata
- Download URL: project_nebula-1.1.1-cp312-cp312-win_amd64.whl
- Upload date:
- Size: 159.2 kB
- Tags: CPython 3.12, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dd585ed6325b98c97fe31690d7d388c5111ce6cf4db395ab7504204e98d9c84e
|
|
| MD5 |
96f421a2272fc85ccd695049a98fd136
|
|
| BLAKE2b-256 |
a3ae8307740ead44e473459cc158042cc56aebe500b4ee130f8c21c3c951497c
|