Skip to main content

Run Django models and views from a single file, and convert it to a full project.

Project description

nanodjango

PyPI Documentation Tests Coverage

  • Write a Django site in a single file, using views, models and admin
  • Run it locally or in production, or share it as a standalone script
  • Automatically convert it to a full Django project when you're ready for it to grow
  • Try it out in your browser at the nanodjango playground

Head to nanodjango.dev to get a high level overview of what nanodjango can do, or you may like to watch a lighting talk.

Quickstart

Install nanodjango:

pip install nanodjango

Write your app in single .py file - for example:

from django.db import models
from nanodjango import Django

app = Django()

@app.admin
class CountLog(models.Model):
    # Standard Django model, registered with the admin site
    timestamp = models.DateTimeField(auto_now_add=True)

@app.route("/")
def count(request):
    # Standard Django function view, or class-based view
    CountLog.objects.create()
    return f"<p>Number of page loads: {CountLog.objects.count()}</p>"

@app.api.get("/add")
def add(request):
    # Django Ninja API support built in
    CountLog.objects.create()
    return {"count": CountLog.objects.count()}

@app.route("/slow/")
async def slow(request):
    import asyncio
    await asyncio.sleep(10)
    return "Async views supported"

Save that as counter.py, then set it up and run it:

nanodjango run counter.py

This will create migrations and a database, and run your project in development mode.

Convert it to a full site

If your project outgrows its single file, you can convert it into a full Django site:

nanodjango convert counter.py path/to/site --name=counter

Share an app

Nanodjango apps are great for sharing examples and prototypes.

Add inline script metadata at the top with your dependencies:

# /// script
# dependencies = ["nanodjango"]
# ///

and call app.run() at the bottom:

if __name__ == "__main__":
    app.run()

Now your app can be run without installing anything, using uv or pipx:

# Run with uv
uv run ./script.py
# or with pipx
pipx run ./script.py

You can still manually install dependencies and run the script directly with Python:

pip install nanodjango
python script.py

Run management commands

Anything you would normally do with manage.py you can do with nanodjango manage:

nanodjango manage script.py check
nanodjango manage script.py makemigrations script
nanodjango manage script.py runserver 0:8000

Run in production

To run nanodjango with production defaults, use nanodjango serve:

nanodjango serve counter.py

This will use gunicorn, or uvicorn if you have async views. It will also turn off settings.DEBUG, and will not serve media files.

Alternatively, you can pass the app directly to a WSGI or ASGI server if you prefer:

gunicorn -w 4 counter:app
uvicorn counter:app

Further reading

For more details, see

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

nanodjango-0.13.0.tar.gz (51.2 kB view details)

Uploaded Source

Built Distribution

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

nanodjango-0.13.0-py3-none-any.whl (49.3 kB view details)

Uploaded Python 3

File details

Details for the file nanodjango-0.13.0.tar.gz.

File metadata

  • Download URL: nanodjango-0.13.0.tar.gz
  • Upload date:
  • Size: 51.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for nanodjango-0.13.0.tar.gz
Algorithm Hash digest
SHA256 d28a6334d3fe8212c0c0a258c71ed5daef8e30467599ae39b9332ca1a23d3cc6
MD5 175232a930dd043631f99da4e40f7e9d
BLAKE2b-256 fffc685200617d1ec07bcc76fa4ce4ccf7680f65319b8893c3631e3d7198555b

See more details on using hashes here.

Provenance

The following attestation bundles were made for nanodjango-0.13.0.tar.gz:

Publisher: pypi.yml on radiac/nanodjango

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file nanodjango-0.13.0-py3-none-any.whl.

File metadata

  • Download URL: nanodjango-0.13.0-py3-none-any.whl
  • Upload date:
  • Size: 49.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for nanodjango-0.13.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5f412025a9bcb998a99a1fc8413b8d5c75a1d6e9ee1f2a117f2bafe09a42298f
MD5 a6844bcf2fb46e009a4da6aa28c85acf
BLAKE2b-256 62a08c92eb5a705dafebec544397d02a7a7fa55a43b8a1f7a8a91a88cfb32151

See more details on using hashes here.

Provenance

The following attestation bundles were made for nanodjango-0.13.0-py3-none-any.whl:

Publisher: pypi.yml on radiac/nanodjango

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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