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.

Changelog

Version 1.1

  • Added caching system (InMemoryCache, CacheMiddleware, @cache decorator)
  • Improved render_template() and Jinja2Templates integration
  • Added automatic static file serving via static_directory parameter
  • 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

project_nebula-1.1.tar.gz (121.2 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.1-cp312-cp312-win_amd64.whl (159.0 kB view details)

Uploaded CPython 3.12Windows x86-64

File details

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

File metadata

  • Download URL: project_nebula-1.1.tar.gz
  • Upload date:
  • Size: 121.2 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.1.tar.gz
Algorithm Hash digest
SHA256 d1bc771b28693ea23b8bab03a17423e962267f10e83ae462164fc4baee7d792f
MD5 be71e17c5658f90cb441696792073f8f
BLAKE2b-256 e8816e7a919839a55b6dbbb88ab6d07c91e452dc9cec9e369677a64238c8e6f3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for project_nebula-1.1-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 ec652cdff7c0dfef1b1d473d25d10c1572320b3ac9071431e85e45f022bd8c33
MD5 a9c58c9ec8bbd1fc3ae1d9ac08727fb1
BLAKE2b-256 cdfa71289b960b75b2940ac2e981911ad9f3b231636ea1b93069859c6f263296

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