Skip to main content

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

project_nebula-1.0.3.tar.gz (114.1 kB view details)

Uploaded Source

Built Distribution

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

project_nebula-1.0.3-cp312-cp312-win_amd64.whl (150.5 kB view details)

Uploaded CPython 3.12Windows x86-64

File details

Details for the file project_nebula-1.0.3.tar.gz.

File metadata

  • Download URL: project_nebula-1.0.3.tar.gz
  • Upload date:
  • Size: 114.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.8

File hashes

Hashes for project_nebula-1.0.3.tar.gz
Algorithm Hash digest
SHA256 8957ec1b240e0f8ffcd58c4f8f3c87f926971b067270d08fe1e8571b03eb31de
MD5 4015e47fa76c8099aa11f96f8e9a3bd5
BLAKE2b-256 306663781c9c3dc52a886ae08a2a8acbb7b2cccf46636452dc2944f9be55b824

See more details on using hashes here.

File details

Details for the file project_nebula-1.0.3-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for project_nebula-1.0.3-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 aaaa0d4921176babe0eb42c39e99833196311ccd70999a6412d62e630fb54729
MD5 fe407249b66b3f05b0e35fba04681fae
BLAKE2b-256 399d34686a9189249748bc41a9c4fb9480b1539ba2ce2c4a26667e14c23d71a4

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