Skip to main content

A lightweight Python web framework with WSGI and ASGI support.

Project description

Creatine

A lightweight Python web framework with WSGI and ASGI support.

Installation

pip install creatine

For development:

pip install creatine[dev]

Quick Start

from creatine import Creatine

app = Creatine()


@app.route("/")
def home(req, resp):
    resp.text = "Hello, World!"


@app.route("/greeting/{name}")
def greeting(req, resp, name):
    resp.text = f"Hello, {name}"


@app.route("/book")
class BookResource:
    def get(self, req, resp):
        resp.text = "Books Page"

    def post(self, req, resp):
        resp.text = "Book created"


@app.route("/json")
def json_handler(req, resp):
    resp.json = {"message": "hello"}


@app.route("/template")
def template_handler(req, resp):
    resp.html = app.template("index.html", context={"title": "Hello"})

Running the Server

# Built-in dev server
creatine runserver app:app

# With Gunicorn (WSGI)
gunicorn app:app

# With Uvicorn (ASGI)
uvicorn app:asgi_app

ASGI & Async Handlers

Creatine supports both sync and async handlers when running under ASGI:

app = Creatine()

asgi_app = app.as_asgi()

@app.route("/async")
async def async_handler(req, resp):
    resp.json = {"async": True}

Middleware

from creatine import Middleware
from creatine.log import LoggingMiddleware

# Built-in request logging
app.add_middleware(LoggingMiddleware)

# Custom middleware
class AuthMiddleware(Middleware):
    def process_request(self, req):
        print(f"Auth check: {req.url}")

    def process_response(self, req, resp):
        print(f"Completed: {resp.status_code}")

app.add_middleware(AuthMiddleware)

ORM

Built-in SQLite ORM for simple data persistence:

from creatine import Database, Table, Column, ForeignKey

db = Database("./app.db")

class Author(Table):
    name = Column(str)
    age = Column(int)

class Book(Table):
    title = Column(str)
    author = ForeignKey(Author)

db.create(Author)
db.create(Book)

author = Author(name="Jane", age=30)
db.save(author)
db.update(author)
db.delete(Author, id=1)

Features

  • WSGI and ASGI compatible
  • Async handler support
  • Parameterized and basic routing
  • Class-based and function-based handlers
  • Built-in SQLite ORM with foreign keys
  • Jinja2 templates
  • Static files via WhiteNoise
  • Middleware pipeline with built-in logging
  • Custom exception handlers
  • Test client (based on Requests)
  • CLI (creatine runserver)
  • GitHub Actions CI with pytest and mypy

Tests

pytest

Project Structure

creatine/
├── __init__.py      # Package exports and version
├── __main__.py      # CLI entry point
├── api.py           # Core Creatine application class
├── asgi.py          # ASGI adapter
├── exceptions.py    # HTTPError
├── log.py           # Logging middleware
├── middleware.py     # Middleware base class
├── orm.py           # SQLite ORM
├── response.py      # Response wrapper
├── route.py         # Route matching and dispatch
└── utils.py         # Static file and test helpers

License

MIT

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

creatine-0.1.0.tar.gz (18.4 kB view details)

Uploaded Source

Built Distribution

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

creatine-0.1.0-py3-none-any.whl (17.3 kB view details)

Uploaded Python 3

File details

Details for the file creatine-0.1.0.tar.gz.

File metadata

  • Download URL: creatine-0.1.0.tar.gz
  • Upload date:
  • Size: 18.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for creatine-0.1.0.tar.gz
Algorithm Hash digest
SHA256 39b14630ba65f1eb4565208625f5f4596b567bf4de33c496faf44067703d408d
MD5 4cc8ab968485fb6483e90f95bae46dc6
BLAKE2b-256 6872b7feb5368492b4886426a0fec53a5c78f31c99cd767bfbcd82f5c0acee40

See more details on using hashes here.

File details

Details for the file creatine-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: creatine-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 17.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for creatine-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 01c11e391dae620642db9e288ebdaf857a0f875cd1cd474562c0cacb5911caee
MD5 e975c65a3d4ebab12489bbe6781475e1
BLAKE2b-256 a268fb52c59655793ffba9d487f881907662759e0f50b16ee200d4afbc6eba2b

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