Skip to main content

Modern Python web framework for building APIs with minimal boilerplate

Project description

Zenith Framework

PyPI version Python 3.12+ License: MIT Tests Documentation

A modern Python web framework with intuitive developer experience and exceptional performance.

๐ŸŽฏ Modern DX: Zero-config setup, database models with chainable queries, one-liner features, and clean architecture patterns - making Python web development incredibly productive.

What is Zenith?

Zenith brings together exceptional productivity, outstanding performance, and full type safety:

  • ๐Ÿš€ Zero-config setup - app = Zenith() just works with intelligent defaults
  • ๐Ÿ—๏ธ Intuitive models - User.where(active=True).order_by('-created_at').limit(10)
  • โšก One-liner features - app.add_auth(), app.add_admin(), app.add_api()
  • ๐ŸŽฏ Enhanced DX - No session management, ZenithModel handles it automatically
  • ๐ŸŽ๏ธ Exceptional performance - 9,600+ req/s with full async support
  • ๐Ÿ›ก๏ธ Production-ready - Security, monitoring, and middleware built-in

๐Ÿš€ Zero-Config Quick Start

pip install zenithweb
from zenith import Zenith
from zenith import Session  # Database session dependency
from zenith.db import ZenithModel  # Modern database models
from sqlmodel import Field
from pydantic import BaseModel
from typing import Optional

# ๐ŸŽฏ Zero-config setup - just works!
app = Zenith()

# โšก Add features in one line each
app.add_auth()    # JWT authentication + /auth/login
app.add_admin()   # Admin dashboard at /admin
app.add_api("My API", "1.0.0")  # API docs at /docs

# ๐Ÿ—๏ธ Modern models with chainable query patterns
class User(ZenithModel, table=True):
    id: Optional[int] = Field(primary_key=True)
    name: str = Field(max_length=100)
    email: str = Field(unique=True)
    active: bool = Field(default=True)

class UserCreate(BaseModel):
    name: str
    email: str
    active: bool = True

# ๐ŸŽจ Clean routes with enhanced DX
@app.get("/")
async def home():
    return {"message": "Modern DX in Python!"}

@app.get("/users")
async def list_users():  # โœจ No session management needed!
    # Clean chaining: User.where().order_by().limit()
    users = await User.where(active=True).order_by('-id').limit(10).all()
    return {"users": [user.model_dump() for user in users]}

@app.post("/users")
async def create_user(user_data: UserCreate):
    # Clean API: User.create() - no session management!
    user = await User.create(**user_data.model_dump())
    return {"user": user.model_dump()}

@app.get("/users/{user_id}")
async def get_user(user_id: int):
    # Automatic 404 handling
    user = await User.find_or_404(user_id)
    return {"user": user.model_dump()}

# ๐Ÿƒโ€โ™‚๏ธ Run it
if __name__ == "__main__":
    import uvicorn
    uvicorn.run(app, host="127.0.0.1", port=8000)

Run with:

uvicorn main:app --reload

๐ŸŽฏ Modern DX Features

๐Ÿš€ Zero-Config Setup (for Development)

app = Zenith()  # Just works! No complex configuration needed
  • Intelligent defaults - Development uses SQLite, auto-generated dev keys
  • Production ready - Set DATABASE_URL and SECRET_KEY env vars for production
  • Automatic middleware - Security, CORS, logging configured automatically
  • Environment-aware - Uses ZENITH_ENV or intelligent detection

๐Ÿ—๏ธ Intuitive Database Models

# Intuitive database operations - seamless chaining!
users = await User.where(active=True).order_by('-created_at').limit(10).all()
user = await User.find_or_404(123)  # Automatic 404 handling
user = await User.create(name="Alice", email="alice@example.com")
  • ZenithModel - Modern ORM with chainable queries
  • Automatic sessions - No manual database session management
  • Type-safe queries - Full async support with SQLModel integration

โšก One-Liner Features

app.add_auth()     # JWT authentication + /auth/login endpoint
app.add_admin()    # Admin dashboard at /admin with health checks
app.add_api()      # API documentation at /docs and /redoc
  • Instant features - Complex functionality in single lines
  • Production-ready - Each feature includes monitoring and security
  • Configurable - Sensible defaults with full customization options

๐ŸŽฏ Clean Dependency Injection

@app.get("/users")
async def get_users(session: AsyncSession = Session):
    # Simple database session injection
    users = await User.all()  # ZenithModel uses the session automatically
    return users
  • Simple patterns - Session for database, Auth for current user
  • Service injection - Inject(ServiceClass) for business logic
  • Type-safe - Full IDE support and autocompletion

๐ŸŽ๏ธ Exceptional Performance

  • ~10,000 req/s - High performance for JSON endpoints
  • ~7,000 req/s - With production middleware stack (71% retention)
  • Async-first - Full async/await with Python 3.12+ optimizations
  • Production tested - Benchmarked with comprehensive test suite

๐Ÿ›ก๏ธ Production-Ready

  • Security by default - CSRF, CORS, security headers automatic
  • Built-in monitoring - /health, /metrics, request tracing
  • Error handling - Structured errors with proper HTTP status codes
  • Testing framework - Comprehensive testing utilities included

๐ŸŒ Full-Stack Support

  • Serve SPAs (React, Vue, SolidJS) with app.spa("dist")
  • WebSocket support with connection management
  • Static file serving with caching
  • Database integration with async SQLAlchemy

๐Ÿ“ Project Structure

Clean organization with zero configuration:

your-app/
โ”œโ”€โ”€ main.py         # app = Zenith() + routes
โ”œโ”€โ”€ models.py       # ZenithModel classes
โ”œโ”€โ”€ services.py     # Business logic (optional)
โ”œโ”€โ”€ migrations/     # Database migrations (auto-generated)
โ””โ”€โ”€ tests/          # Testing with built-in TestClient

Or traditional clean architecture:

your-app/
โ”œโ”€โ”€ main.py         # Application entry point
โ”œโ”€โ”€ models/         # ZenithModel classes
โ”œโ”€โ”€ services/       # Service classes with @Service decorator
โ”œโ”€โ”€ routes/         # Route modules (optional)
โ”œโ”€โ”€ middleware/     # Custom middleware
โ””โ”€โ”€ tests/          # Comprehensive test suite

Performance

Verified Benchmark Results:

  • JSON endpoints: ~10,000 req/s (9,917 req/s measured)
  • Simple endpoints: ~8,000 req/s (7,743 req/s measured)
  • With middleware: ~7,000 req/s (71% retention, 29% overhead)

Tested on Apple M3 Max, Python 3.12, using performance test suite

Run your own benchmarks:

uv run pytest tests/performance/ -v

Performance varies by hardware, middleware configuration, and application complexity.

Documentation

๐Ÿ“š Examples

๐Ÿ”ฅ Modern DX Examples:

๐Ÿš€ Complete Examples:

CLI Tools

# Create new project with secure defaults
zen new my-api

# Generate secure SECRET_KEY
zen keygen

# Show configuration and environment info
zen config --all

# Generate boilerplate code
zen generate model User
zen generate service UserService
zen generate graphql UserSchema

# Development server with hot reload
zen dev

# Production server
zen serve --workers 4

Installation

# Basic installation
pip install zenithweb

# With production dependencies
pip install "zenithweb[production]"

# With development tools
pip install "zenithweb[dev]"

Production Deployment

Docker

FROM python:3.12-slim

WORKDIR /app
COPY . .
RUN pip install "zenithweb[production]"

CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]

Environment Configuration

from zenith import Zenith

app = Zenith()

# Environment-specific behavior:
# development (or dev): Enhanced error reporting, auto-generated secrets
# production (or prod): Optimized for deployment, requires SECRET_KEY
# test: Testing mode with rate limiting disabled
# staging: Production-like with enhanced monitoring

# Manual configuration if needed
from zenith.config import Config
app = Zenith(
    config=Config(
        database_url=os.getenv("DATABASE_URL"),
        redis_url=os.getenv("REDIS_URL"),
        secret_key=os.getenv("SECRET_KEY")
        # debug automatically set based on ZENITH_ENV
    )
)

Contributing

We welcome contributions! Please see our Contributing Guide.

git clone https://github.com/nijaru/zenith.git
cd zenith
pip install -e ".[dev]"
pytest  # Run tests

Status

Latest Version: v0.0.10 Python Support: 3.12-3.14 Test Suite: 100% passing (900 tests) Performance: ~10,000 req/s JSON endpoints, ~7,000 req/s with middleware Architecture: Clean separation with Service system and simple dependency patterns

Zenith is production-ready with comprehensive middleware, performance optimizations, and clean architecture patterns for modern Python applications.

License

MIT License. See LICENSE for details.

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

zenithweb-0.0.11.tar.gz (306.8 kB view details)

Uploaded Source

Built Distribution

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

zenithweb-0.0.11-py3-none-any.whl (215.0 kB view details)

Uploaded Python 3

File details

Details for the file zenithweb-0.0.11.tar.gz.

File metadata

  • Download URL: zenithweb-0.0.11.tar.gz
  • Upload date:
  • Size: 306.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.13

File hashes

Hashes for zenithweb-0.0.11.tar.gz
Algorithm Hash digest
SHA256 05ddb29762680b8a16a1e802be38a47774d4c550d13ed3438a5c5d18dd11ad25
MD5 e270d13a792852224e6eb9b6c47438d1
BLAKE2b-256 dd864bd4b1d179a6d26311020f962d5889895dc2541d88cc717914f9629ec42a

See more details on using hashes here.

File details

Details for the file zenithweb-0.0.11-py3-none-any.whl.

File metadata

  • Download URL: zenithweb-0.0.11-py3-none-any.whl
  • Upload date:
  • Size: 215.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.13

File hashes

Hashes for zenithweb-0.0.11-py3-none-any.whl
Algorithm Hash digest
SHA256 88fc8e8533853d45fdd502d8b99d3218178937c2505369595ac69e2199c5ca7f
MD5 ae162fdaeea14e30710ba164807593c1
BLAKE2b-256 42bb64b977cce4919d2375c4bffd0d9855ed5b79a19a9a3b5b191e8f5e92de59

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