Skip to main content

dorm

PyPI - Version PyPI - Status PyPI - Python Version PyPI - Versions from Framework Classifiers GitHub License ci cd Stars

dorm is a minimal wrapper around Django that allows you to use its ORM independently—no need for the full Django framework. Quickly integrate Django's robust ORM into non-Django projects with a simple settings.py file.

Note: This project is under active development. Use with caution.

Why dorm?

The Django ORM is rich with features like automatic schema migrations and effortless joins. Other python ORMs, like SQLAlchemy, often felt less intuitive in comparison.

The idea for dorm emerged from a desire to use Django's ORM without unnecessary overhead like manage.py, views.py, or complex settings. With dorm, you get the power of Django ORM, simplified for standalone use.

Note: Since dorm is a lightweight wrapper around Django, all of Django's features remain accessible if you choose to use them. dorm ensures you can leverage Django's ORM with minimal setup and footprint.


Installation

pip install dorm-project "django>=5.1.0,<5.2.0" 
# Install Django to a specific version to ensure compatibility and avoid potential issues.  

Quick Start

1. Add a settings.py file

Automatically (recommended) add using dorm init command:

cd <proj-root>
dorm init 

OR

Manually add settings.py file, ensure INSTALLED_APPS and DATABASES values are set:

# <proj-root>/settings.py
from pathlib import Path

BASE_DIR = Path(__file__).parent.resolve()

INSTALLED_APPS = []
DATABASES = {
    "default": {
        "ENGINE": "django.db.backends.sqlite3",
        "NAME": BASE_DIR / "db.sqlite3",
    }
}

2. Setup dorm

Call the dorm.setup() method in your project's entry point (e.g., main.py, app.py, or the script that starts your application) to initialize the Django ORM and set up the necessary database connections. This step is essential for using the ORM independently of the full Django framework.

If you're interacting with the project via the dorm CLI (e.g., running migrations or using the shell or any custom Django management command), dorm.setup() is automatically called for you.

Note: Ensure that models are imported after calling dorm.setup() to avoid any initialization issues.

Note: Ensure you call dorm or your entrypoint from the project root (where the settings.py is). If you want to call from somewhere else, then explicitly pass settings_dir to dorm.setup(settings_dir=...)

Here's how you might set it up in your entry point:

# entrypoint - main.py, script.py, project.__init__.py etc
import dorm

def main():
    dorm.setup()
    
    # You can start importing and using your models from here...
    

if __name__ == "__main__":
    main() 

3. Define models

Create a models.py in a package and add Django models:

mkdir -p blog
touch blog/models.py

Example model:

# blog/models.py
from django.db import models

class Post(models.Model):
    title = models.CharField(max_length=100)
    slug = models.SlugField(unique=True)
    body = models.TextField()

4. Register your app

Add your package to INSTALLED_APPS in settings.py:

# <proj-root>/settings.py
INSTALLED_APPS = [
    "blog",
]

5. Run migrations

Use dorm CLI to manage migrations (or any django management command - like shell, test, dbshell, etc:

dorm makemigrations
dorm migrate

6. Use the ORM

Access your models in an interactive shell:

dorm shell

Example:

>>> from blog.models import Post
>>> post = Post(title="Hello", slug="hello-world", body="This is dorm!")
>>> post.save()
>>> Post.objects.all()

7. Write unittest using the ORM

Example:

# blog/tests.py
from django.test import TestCase

from blog.models import Post

class TestPostModel(TestCase):
    def test_creating_object(self):
        post = Post()
        post.title = "Fake title"
        post.slug = "fake-title"
        post.post = "fake body"
        post.save()

Run test with Django test runner via dorm CLI:

dorm test

Future Plans

  • Features to make dorm feasible with other web framework - with proper connection pooling and transactional requests. full
  • Allow users to access admin site

Metadata

Release files for dorm-project 0.2.14

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

Source distribution (sdist)

Source distribution for dorm-project 0.2.14
File Size Uploaded
dorm_project-0.2.14.tar.gz 15.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for dorm-project 0.2.14
File Interpreter ABI Platform
dorm_project-0.2.14-py3-none-any.whl Python 3 none any Details

Total release size: 23.2 kB

Release files / dorm_project-0.2.14.tar.gz

Download URL dorm_project-0.2.14.tar.gz
Size 15.7 kB
Tags Source
SHA-256 checksum
How to use checksums
ba813a20a0df38b3b09c9d730ee7478066a40d356e31da26dc233c9b6b408b08
BLAKE2b-256 checksum
How to use checksums
7d77d44d14659fef6d6e6878a421f62a2fc1be2055c96a69399c7dd5da077002
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.5.14

Release files / dorm_project-0.2.14-py3-none-any.whl

Download URL dorm_project-0.2.14-py3-none-any.whl
Size 7.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4017e410eaf122b15013fffb832bcc3247776a14ad5e79001338ce27cd839b42
BLAKE2b-256 checksum
How to use checksums
6bedef19b5f3558d71e790dc87faf625228bdd85271bb805fe7c631ee4dab105
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.5.14

Release history Release notifications | RSS feed

This release

0.2.14 This release

2 release files

0.2.9

2 release files

0.2.8

2 release files

0.2.7

2 release files

0.2.6

2 release files

0.2.5

2 release files

0.2.4

2 release files

0.2.3

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

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