Skip to main content

Unchained

Unchained - Modern Single-File Django Framework

PyPI version

Unchained is a framework that lets you build complete Django applications in a single file, without the traditional project and app structure. Write modern Python web apps with minimal boilerplate.

Key Features

Single-File Application

Build production-ready Django applications in a single file, similar to modern frameworks like Flask or FastAPI:

from unchained import Unchained
from unchained.models.base import BaseModel
from django.db import models

class User(BaseModel):
    name = models.CharField(max_length=255)
    email = models.EmailField(unique=True)

app = Unchained()

@app.get("/hello/{name}")
def hello(name: str):
    return {"message": f"Hello {name}!"}

app.crud(User)  # Auto-generate CRUD endpoints

Automatic CRUD Operations

Generate complete REST API endpoints for your models with a single line of code:

app.crud(User)  # Creates GET, POST, PUT, DELETE endpoints

This creates:

  • GET /api/users - List all users
  • GET /api/users/{id} - Get a specific user
  • POST /api/users - Create a new user
  • PUT /api/users/{id} - Update a user
  • DELETE /api/users/{id} - Delete a user

Powerful Dependency Injection

Use Python type annotations for clean, testable dependencies:

from typing import Annotated
from unchained import Depends

def get_current_user() -> User:
    # Logic to get user
    return user

@app.get("/profile")
def profile(user: Annotated[User, Depends(get_current_user)]):
    return {"user": user}

Built-in CLI Tool

Manage your application with a powerful command-line interface:

# Start the server
unchained start main:app

# Database migrations
unchained migrations create
unchained migrations apply

# Create admin user
unchained createsuperuser

Why Unchained?

The Django Project/App Pain

Traditional Django development requires a rigid structure:

myproject/
├── manage.py
├── myproject/
│   ├── __init__.py
│   ├── settings.py
│   ├── urls.py
│   └── wsgi.py
└── myapp/
    ├── __init__.py
    ├── admin.py
    ├── apps.py
    ├── migrations/
    ├── models.py
    ├── tests.py
    └── views.py

This approach comes with significant overhead:

  • Running multiple commands to set up a project (django-admin startproject, python manage.py startapp)
  • Manually connecting apps, updating settings files, and configuring URLs
  • Working across many files for even simple features
  • Constant switching between files for models, views, and URLs

The Unchained Solution

All of Django's power, none of the structure overhead.

# One file. That's it.
from unchained import Unchained
from django.db import models

class Post(models.Model):
    title = models.CharField(max_length=100)
    content = models.TextField()

app = Unchained()

@app.get("/posts")
def list_posts():
    return Post.objects.all()

# No manage.py, no settings.py, no urls.py, no apps.py

Installation

pip install unchained

Admin Interface

Unchained includes Django's powerful admin interface out of the box with a modern UI theme (Django Jazzmin). The admin interface is automatically available at /admin/ and lets you manage your models with a user-friendly UI.

Registering Models

You can easily register your models with the admin interface:

from unchained import Unchained
from unchained.models.base import BaseModel
from django.db import models
from django.contrib.admin import ModelAdmin

# Define your model
class Product(BaseModel):
    name = models.CharField(max_length=255)
    price = models.DecimalField(max_digits=10, decimal_places=2)
    description = models.TextField(blank=True)

# Create custom admin class (optional)
class ProductAdmin(ModelAdmin):
    list_display = ('name', 'price')
    search_fields = ('name',)

# Create application
app = Unchained()

# Register model with the admin
app.admin.register(Product, ProductAdmin)

With this setup, you can log in to /admin/ and manage your models through a clean, intuitive interface.

Default Features

The admin interface provides:

  • A modern dark/light theme with customizable UI
  • CRUD operations for your models
  • Search, filtering, and sorting
  • User authentication and permissions
  • Easy customization with ModelAdmin classes

Simplifying CLI Commands

To avoid specifying main:app in every CLI command, you can configure Unchained to automatically detect your application:

Using Environment Variables

Set the UNCHAINED_APP_PATH environment variable:

# Unix/Linux/MacOS
export UNCHAINED_APP_PATH=main:app

# Windows
set UNCHAINED_APP_PATH=main:app

After setting this, you can use CLI commands without specifying the app path:

unchained start
unchained migrations apply

Using pyproject.toml

Add an [tool.unchained] section to your pyproject.toml file:

[tool.unchained]
app_path = "main:app"

With this configuration, Unchained will automatically detect your app path, allowing you to run commands like:

unchained start
unchained migrations create

All Features

  • Single-file Django applications - No project setup or app creation required
  • Fast API development with Django Ninja and automatic OpenAPI documentation
  • Built-in CLI tool for managing your application
  • Dependency Injection using Python type annotations
  • Automatic CRUD operations for your models
  • Modern Admin interface with beautiful UI
  • ASGI server with hot-reload for development

Complete Quickstart Example

  1. Create a file named main.py:
from typing import Annotated

from unchained import Depends, Unchained
from unchained.models.base import BaseModel
from django.db import models
from django.contrib.admin import ModelAdmin

# Define your models
class User(BaseModel):
    name = models.CharField(max_length=255)
    email = models.EmailField(unique=True)

# Custom admin class
class UserAdmin(ModelAdmin):
    list_display = ('name', 'email')
    search_fields = ('name', 'email')

# Create your application
app = Unchained()

# Register model with admin
app.admin.register(User, UserAdmin)

# Define dependencies
def get_greeting() -> str:
    return "Hello"

# Create API endpoints
@app.get("/hello/{name}")
def hello(name: str, greeting: Annotated[str, Depends(get_greeting)]):
    return {"message": f"{greeting} {name}!"}

# Generate CRUD endpoints automatically
app.crud(User)
  1. Run the development server:
unchained start main:app
  1. Access your application:

CLI Commands

Unchained comes with a powerful CLI tool to help manage your application:

Starting the Server

# Basic usage
unchained start main:app

# Custom host and port
unchained start main:app --host 0.0.0.0 --port 5000

# Disable auto-reload
unchained start main:app --no-reload

Database Migrations

# Create migrations
unchained migrations create main:app [name]

# Apply migrations
unchained migrations apply main:app [app_label] [migration_name]

# Show migration status
unchained migrations show main:app [app_label]

User Management

# Create a superuser for admin access
unchained createsuperuser main:app [username] [email]

Utilities

# Check version
unchained version

API Documentation

Once your server is running, you can access the auto-generated API documentation at:

Configuration

Unchained can be configured through:

  1. Environment variables (e.g., UNCHAINED_APP_PATH)
  2. A pyproject.toml file with [tool.unchained] section
  3. Command-line arguments

Learn More

For more information, check out the documentation:

Metadata

Release files for unchained 0.1.9

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for unchained 0.1.9
File Size Uploaded
unchained-0.1.9.tar.gz 152.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for unchained 0.1.9
File Interpreter ABI Platform
unchained-0.1.9-py3-none-any.whl Python 3 none any Details

Total release size: 177.2 kB

Release files / unchained-0.1.9.tar.gz

Download URL unchained-0.1.9.tar.gz
Size 152.6 kB
Tags Source
SHA-256 checksum
How to use checksums
757ee024968cef070a2f0523c823a840764630e54cd8b87be241c82ff4a136e6
BLAKE2b-256 checksum
How to use checksums
e4b5abb7f912dddc691e1a386d0d6b20943adfbeaa20e38f8f4adea98bd95f05
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / unchained-0.1.9-py3-none-any.whl

Download URL unchained-0.1.9-py3-none-any.whl
Size 24.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e1281a0afeb7cf2f41bc710ade16ba3b5c247dc3e486583ff7e1298ad81207f6
BLAKE2b-256 checksum
How to use checksums
7c9b00b019911ed19321f8ec94deb28eb6991abf7e90da46b1d729409db88976
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Release history Release notifications | RSS feed

This release

0.1.9 This release

2 release files

0.1.8

2 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.5

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page