django-forge-core
English | Français
Runtime foundation for Django Forge projects: small building blocks that generated code imports, also usable on their own in any Django project.
It provides three things:
settings.pyconfiguration read from the environment, with clear errors;- common abstract models (timestamps, UUID, soft delete);
- typed business errors meant to be used with pycatch (
Result), and their conversion into DRF responses.
Installation
uv add django-forge-core
uv add "django-forge-core[drf]" # with the Django REST Framework integration
Python 3.12 or later, Django 5.0 or later. Projects created with forge init get it through the Forge CLI.
Configuration from the environment
# settings.py
from forge_core.conf import env, env_bool, env_list, env_int, deep_merge, current_environment
SECRET_KEY = env("SECRET_KEY") # ImproperlyConfigured if missing
DEBUG = env_bool("DEBUG", default=False)
ALLOWED_HOSTS = env_list("ALLOWED_HOSTS", default=["localhost"])
DB_PORT = env_int("DB_PORT", default=5432)
| Function | Purpose |
|---|---|
env(name, default, cast) |
Value converted with cast; default is returned as is when the variable is missing |
env_bool |
1/true/yes/on/oui or 0/false/no/off/non (case insensitive) |
env_int, env_float |
Numbers |
env_list(name, sep=",") |
List of strings, without spaces or empty items |
current_environment() |
Value of FORGE_ENV (dev by default) |
deep_merge(*layers) |
Merges configuration layers, nested dictionaries recursively |
A missing variable without a default raises ImproperlyConfigured naming the variable, and an invalid value reports both the name and the raw value.
Layers example:
BASE = {"LOGGING": {"version": 1, "root": {"level": "INFO"}}}
PROD = {"LOGGING": {"root": {"level": "WARNING"}}}
layers = {"dev": BASE, "prod": deep_merge(BASE, PROD)}
globals().update(layers[current_environment()])
Abstract models
from django.db import models
from forge_core.models import SoftDeleteModel, TimeStampedModel, UUIDModel
class Article(UUIDModel, TimeStampedModel, SoftDeleteModel):
title = models.CharField(max_length=200)
TimeStampedModel:created_at,updated_at.UUIDModel: UUID4 primary key.SoftDeleteModel:delete()setsdeleted_at.Article.objectsonly sees active rows,Article.all_objectssees everything. Methodsrestore()andhard_delete(), and on QuerySetsalive(),dead(),hard_delete().
These classes are abstract: no migration of their own, and forge_core does not need to be in INSTALLED_APPS.
Typed errors and pycatch
from pycatch import Err, Ok, Result
from forge_core.errors import NotFound
def get_article(pk: int) -> Result[Article, NotFound]:
try:
return Ok(Article.objects.get(pk=pk))
except Article.DoesNotExist:
return Err(NotFound(f"Article {pk} not found"))
Provided errors: ValidationFailed (400), Unauthenticated (401), PermissionRefused (403), NotFound (404), Conflict (409). Each carries a stable code and an HTTP status; ForgeError is the base class for your own.
Django REST Framework
from forge_core.drf import respond
class ArticleView(APIView):
def get(self, request, pk):
return respond(get_article(pk))
respond turns Ok(value) into a response and Err(ForgeError) into {"code": ..., "detail": ...} with the right status. So that a ForgeError raised inside a view produces the same response:
REST_FRAMEWORK = {"EXCEPTION_HANDLER": "forge_core.drf.exception_handler"}
Development
uv sync
uv run ruff check src tests
uv run pytest --cov=forge_core --cov-report=term-missing
License
Metadata
Release files for django-forge-core 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| django_forge_core-0.1.0.tar.gz | 28.2 kB | With provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| django_forge_core-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 37.2 kB
Release files / django_forge_core-0.1.0.tar.gz
| Download URL | django_forge_core-0.1.0.tar.gz |
|---|---|
| Size | 28.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b08f375a4e51f74e1abf4a4f6b76470a2ae388c083dc670da93948f2cef441aa
|
|
BLAKE2b-256 checksum How to use checksums |
255e7c7440e423963c0606bd1180de2bff54737e798bef94ae08b3fecd5df03d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 15, 2026.
Transparency logRelease files / django_forge_core-0.1.0-py3-none-any.whl
| Download URL | django_forge_core-0.1.0-py3-none-any.whl |
|---|---|
| Size | 9.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
88fbf089cb21ce6543559f8ab3739772f728563907727f480387bb6fdfc3d308
|
|
BLAKE2b-256 checksum How to use checksums |
61b55aeb7fe79638024e33a143bc99ac59274281f980f0cbae36b7d0ceed9c7f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 15, 2026.
Transparency logSecurity for django-forge-core 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for django_forge_core-0.1.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 15, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.