Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

core-package

Author: puzzllium · puzzllium@gmail.com · LinkedIn

Reusable Django/Ninja apps — session-JWT auth, users, RBAC, audit logging, base models and optional Socket.IO — that you install into your own Django project. It's the foundation for the site packages (blog, portfolio, company, ecommerce, ...). It is a package, not a project: there are no settings, urls, or manage.py in it.

Install

Requires Python 3.10+ and Django 5.2.

Base package

pip install core-package

Installs the required apps (apps.core, apps.users, apps.roles, apps.events, apps.contacts) and their dependencies only — no Socket.IO, no static-file middleware, no database driver beyond Django's built-in sqlite, no ASGI server.

Extras

Each extra adds one optional feature. Quote the argument so the shell doesn't expand the brackets.

Command Adds Needed for
pip install "core-package[realtime]" python-socketio, python-engineio apps.realtime in INSTALLED_APPS and with_socketio() in asgi.py
pip install "core-package[static]" whitenoise apps.core.middleware.AsyncWhiteNoiseMiddleware
pip install "core-package[postgres]" psycopg[binary] a PostgreSQL DATABASES entry
pip install "core-package[redis]" django-redis, redis Redis cache/sessions and multi-worker Socket.IO (REDIS_URL)
pip install "core-package[server]" uvicorn[standard] running the project with uvicorn
pip install "core-package[all]" all five above everything
pip install "core-package[dev]" realtime, static, pytest, pytest-django, pytest-asyncio running this package's own tests

Extras combine with commas:

pip install "core-package[realtime,server]"             # local development with Socket.IO
pip install "core-package[static,server]"               # local development without Socket.IO
pip install "core-package[postgres,redis,static,server]" # production without Socket.IO
pip install "core-package[all]"                          # production with Socket.IO

Pinning a version

In a project's requirements.txt, pin the exact version so every machine installs the same thing:

core-package[all]==0.2.1

Through a site package

Site packages depend on core-package, so installing one installs core-package too (base package, no extras). Add the extras you want alongside it:

pip install company-portfolio-package "core-package[realtime,server]"

Working on core-package itself

From a clone of this repo, an editable install picks up code changes without reinstalling:

pip install -e ".[dev]"

Creating a project

core-package is installed into a normal Django project. The steps below build one from scratch (here Core/myproject, next to the Packages/ folder).

1. Folder and virtualenv

mkdir myproject && cd myproject
python -m venv .venv
source .venv/bin/activate

2. Install core-package

pip install "core-package[server]"             # without Socket.IO
pip install "core-package[realtime,server]"    # with Socket.IO

server installs uvicorn. pip install "core-package[all]" installs every extra.

3. Create the Django project

django-admin startproject config .

4. config/settings.py

from apps.core.defaults import CORE_APPS, CORE_MIDDLEWARE, PASSWORD_HASHERS  # noqa: F401

INSTALLED_APPS = [
    "unfold",  # must come before django.contrib.admin
    "django.contrib.admin",
    "django.contrib.auth",
    "django.contrib.contenttypes",
    "django.contrib.sessions",
    "django.contrib.messages",
    "django.contrib.staticfiles",
    *CORE_APPS,          # ninja, apps.core, apps.events, apps.users, apps.roles
    # "apps.contacts",   # optional: contact form
    # "apps.realtime",   # optional: Socket.IO (needs core-package[realtime])
]

MIDDLEWARE = [
    # ... Django's default middleware, unchanged ...
    *CORE_MIDDLEWARE,    # JSON request log
]

AUTH_USER_MODEL = "users.User"

MEDIA_URL = "media/"
MEDIA_ROOT = BASE_DIR / "media"

5. config/urls.py

from django.contrib import admin
from django.urls import path

from apps.core.api import create_api

api = create_api(title="My Site API")

urlpatterns = [
    path("admin/", admin.site.urls),
    path("api/", api.urls),
]

create_api() adds session-JWT auth, the shared error format, GET /health and the core routers (/auth, /roles, /events, plus /contacts if that app is installed). Any NinjaAPI keyword (title, version, docs_url, ...) is passed through.

6. Socket.IO (optional)

Skip this step if you don't want sockets; nothing else depends on it. Otherwise install core-package[realtime], uncomment "apps.realtime" in INSTALLED_APPS, and replace config/asgi.py with:

import os

from django.core.asgi import get_asgi_application

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings")
django_asgi_app = get_asgi_application()

from apps.realtime.asgi import with_socketio  # noqa: E402

application = with_socketio(django_asgi_app)

7. Database and admin user

python manage.py migrate
python manage.py seed_roles        # default "admin" and "user" roles
python manage.py createsuperuser

8. Run

uvicorn config.asgi:application --reload   # required for Socket.IO
python manage.py runserver                 # fine without Socket.IO
  • API docs: http://localhost:8000/api/docs
  • Admin: http://localhost:8000/admin/

9. Add site packages (e.g. a company portfolio site)

Site packages are installed the same way and mounted on the API. For a company site, install company-portfolio-package (it pulls in portfolio-package and blog-package), then:

# settings.py: after *CORE_APPS, in this order
    *CORE_APPS,
    "blog",
    "portfolio",
    "company",
# urls.py
from blog.api import router as blog_router
from company.api import router as company_router
from portfolio.api import router as portfolio_router

api = create_api(title="My Site API")
api.add_router("/blog", blog_router)
api.add_router("/portfolio", portfolio_router)
api.add_router("/company", company_router)
python manage.py migrate

10. Frontend on another origin (CORS)

CORS is the host project's job, not the package's:

pip install django-cors-headers
INSTALLED_APPS += ["corsheaders"]
# put "corsheaders.middleware.CorsMiddleware" before CommonMiddleware in MIDDLEWARE
CORS_ALLOWED_ORIGINS = ["http://localhost:3000"]
CSRF_TRUSTED_ORIGINS = ["http://localhost:3000"]
CORS_ALLOW_CREDENTIALS = True   # auth uses the session cookie

Settings

All optional — the package falls back to these defaults (apps/core/conf.py):

Setting Default
JWT_SIGNING_KEY SECRET_KEY
JWT_ACCESS_TOKEN_LIFETIME_MINUTES 60
REDIS_URL "" (Socket.IO uses the in-process manager)
CORS_ALLOWED_ORIGINS [] (Socket.IO allowed origins)
KAVENEGAR_API_KEY "" (OTP codes are logged instead of sent)
KAVENEGAR_OTP_TEMPLATE "verify"

For the JSON audit log file, set LOGGING = build_logging_config(BASE_DIR / "logs") from apps.core.logging.

What's inside

App Required Purpose
apps.core yes Session-bound JWT auth, permissions, middleware, pagination, throttling, exceptions, audit logging, SMS helper, create_api()
apps.users yes User model and user/auth API
apps.roles yes Role-based access control (RBAC)
apps.events yes Audit events model, API and admin
apps.contacts no Contact messages model, API and admin
apps.realtime no Socket.IO server with session/JWT authentication

Development

pip install -e ".[dev]"
pytest          # runs against testproject/ (not shipped in the wheel)

Dependencies

Version ranges are used (this is a library), so it won't conflict with the host project.

Required

Package Used for
Django >=5.2,<5.3 Web framework
django-ninja >=1.4,<2 REST API layer
asgiref >=3.8 Async support
email-validator >=2.2,<3 Email validation
argon2-cffi >=23 Password hashing
PyJWT >=2.8,<3 JWT tokens
django-unfold >=0.60 Admin theme
Pillow >=10 Image handling
requests >=2.31,<3 SMS (Kavenegar) HTTP client

Optional extras

Extra Installs For
realtime python-socketio, python-engineio apps.realtime
static whitenoise apps.core.middleware.AsyncWhiteNoiseMiddleware
postgres psycopg[binary] PostgreSQL
redis django-redis, redis Cache/sessions, multi-worker Socket.IO
server uvicorn[standard] ASGI server
all all of the above

License

MIT. See LICENSE.

Metadata

Release files for core-package 0.3.0.dev1

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

Source distribution (sdist)

Source distribution for core-package 0.3.0.dev1
File Size Uploaded Provenance Actions
core_package-0.3.0.dev1.tar.gz 85.0 kB With provenance Details for core_package-0.3.0.dev1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for core-package 0.3.0.dev1
File Interpreter ABI Platform Actions
core_package-0.3.0.dev1-py3-none-any.whl Python 3 none any Details for core_package-0.3.0.dev1-py3-none-any.whl

Total release size: 196.0 kB

Release files / core_package-0.3.0.dev1.tar.gz

Download URL core_package-0.3.0.dev1.tar.gz
Size 85.0 kB
Tags Source
SHA-256 checksum
How to use checksums
bd5065d066d1eca0fb9304a553a5cac611cbe3f74ae57c68ed4d3d70176b1a0f
BLAKE2b-256 checksum
How to use checksums
a39d417c53de9cf47b6abec4b4faafe5b627f6ea84757167c3e0fa3145816f2e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 17, 2026.

Transparency log

Release files / core_package-0.3.0.dev1-py3-none-any.whl

Download URL core_package-0.3.0.dev1-py3-none-any.whl
Size 111.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9759b934e69971371cf65df317e6c4f1332d7eef2182ac8ef131b97818256689
BLAKE2b-256 checksum
How to use checksums
4605102dfc886e3384ca287c4585fe2161449c33bde5cc128ca66d73972dfdc3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 17, 2026.

Transparency log

Security for core-package 0.3.0.dev1

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

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for core_package-0.3.0.dev1.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 Nov 17, 2026.

Transparency log

A 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.

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