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
Nebula
Simple ASGI micro framework for Python, which supports both http and websockets.
Update changelog:
Added app.run(), mount(), render_template(), Jinja2Templates Added new response types: PlainTextResponse, StreamingResponse, FileResponse, RedirectResponse
Installation
pip install project-nebula
Usage
from nebula import Nebula, 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}"})
@app.get("/api/items/{name:str}")
async def get_item(request):
name = request.path_params["name"] # str
return JSONResponse({"name": name, "type": "item"})
@app.get("/api/score/{value:float}")
async def get_score(request):
value = request.path_params["value"] # float
return JSONResponse({"score": value, "doubled": value * 2})
# Sync handler example
@app.get("/api/sync")
def sync_handler(request):
return JSONResponse({"type": "sync", "message": "I'm synchronous!"})
# New response types
from nebula import PlainTextResponse, StreamingResponse, FileResponse, RedirectResponse
@app.get("/text")
async def text(request):
return PlainTextResponse("Plain text response")
@app.get("/stream")
async def stream(request):
async def generate():
for i in range(10):
yield f"Line {i}\n"
return StreamingResponse(generate())
@app.get("/download")
async def download(request):
return FileResponse("file.pdf", filename="download.pdf")
@app.get("/redirect")
async def redirect(request):
return RedirectResponse("https://example.com")
# Mount static files
app.mount("/static", directory="static")
# Template rendering
from nebula import Jinja2Templates
templates = Jinja2Templates(directory="templates")
@app.get("/template")
async def template(request):
return templates.TemplateResponse("index.html", {"request": request, "title": "Home"})
# Run server directly
if __name__ == "__main__":
app.run(host="0.0.0.0", port=8000, reload=True)
Run
python examples/app.py
Or with uvicorn directly:
uvicorn examples.app:app --reload
Or using app.run():
python your_app.py
Features
- ASGI compliant
- JSON and HTML responses
- Path parameters support (
/users/{id}) - Request body parsing (JSON, text)
- Multiple HTTP methods (GET, POST, PUT, DELETE)
- Static file mounting
- Template rendering (Jinja2)
- Multiple response types (PlainText, Streaming, File, Redirect)
- 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.0.2.tar.gz.
File metadata
- Download URL: project_nebula-1.0.2.tar.gz
- Upload date:
- Size: 114.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3f28184b41be7163a982a66a0a2de348a4472748eed9dfda940e224137c64b36
|
|
| MD5 |
6fa4df9e965eefdf6b91a1291c0f7322
|
|
| BLAKE2b-256 |
0ccc4b65a2d12307f38c9ea6328bfc7114ad1a2c94d6803e682f5b9f12e4e342
|
File details
Details for the file project_nebula-1.0.2-cp312-cp312-win_amd64.whl.
File metadata
- Download URL: project_nebula-1.0.2-cp312-cp312-win_amd64.whl
- Upload date:
- Size: 150.5 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 |
42ba19ca6eb07dcabee4faaf61b76951ac7d51f42ea00504273af1997d9c3880
|
|
| MD5 |
e165ff6a60acae72a57a8b5fdf858419
|
|
| BLAKE2b-256 |
720b51a4921f9b69335fc1166f10428d402854ab3bd25bcec3065b1a9cc2b344
|