Core framework package (import as core_framework)
Project description
Core framework
Reusable backend core published as the Python distribution core-framework (pyproject.toml). Import the implementation as core_framework (see Core framework migration, Package API, and CHANGELOG for version history).
Repository: github.com/NepNepFFXIV/core-framework
License: MIT — see LICENSE.
Install
Pin core-framework from Git (use a tag or commit for reproducible builds):
uv add "core-framework @ git+https://github.com/NepNepFFXIV/core-framework.git@v1.2.0"
pip install "core-framework @ git+https://github.com/NepNepFFXIV/core-framework.git@v1.2.0"
After it resolves, load Settings, call init_app(settings) from core_framework.main in your app factory, and apply bundled core schema from the host project root with uv run cf-alembic (see Host integration and Package API).
To hack on this repo: clone it, run uv sync (or pip install -e .), keep a local config.toml, run uv run cf-alembic, then make run or serve core_framework.asgi:app.
Host integration
Hosts depend on core-framework, own config and the DB, and import core_framework. Details: Core framework migration.
- Dependency — Pin
core-framework(path, Git tag, or index) and lock deploys (uv.lock, etc.). - Settings — Use
Settingsfromcore_framework.core.settings. Default loading usesconfig.tomland environment variables; env wins over TOML for the same field (see Architecture decisions). Subclass only if you need extra host-only fields; otherwiseSettings()/model_validateis enough. Subclasses may needmodel_configtweaks (e.g.toml_file) if paths differ. - App — Call
init_app(settings)fromcore_framework.maininside the host’s ownmain.py(or app factory). Importingcore_framework.mainhas no side effects; onlyinit_app(settings)runs the bootstrap. Do not importcore_framework.asgi— that module exists sofastapi dev/uvicorncan serve the library’s own default-settings app standalone, and it eagerly loadscore-framework’s ownconfig.tomlat import time. Do not mountrouteralone without the same bootstrap — see Package API. - Database — Apply core schema from the host root (where
config.tomlloads):uv run cf-alembic. Host-only tables: host migrations; order with core (Database and Alembic). - Worker —
WorkerSettingsclass incore_framework.worker.main(run witharq core_framework.worker.main.WorkerSettings). Bootstrap (configure_application_dependencies, pool connects,init_cashews_backend) runs inon_startup, not at import time. ARQ exposesctx["redis"]for enqueue in cron handlers;CoreRuntime.redis_queueis a separate connected pool for runtime parity with the API — see Architecture — ARQ and CoreRuntime queue clients. - API surface — Only Package API imports are stable; see CHANGELOG.
- Upgrading / new
Settingsfields — When you bumpcore-framework, read CHANGELOG for that release (and any required migration notes). NewSettingskeys are announced there: required keys must be added to the host’sconfig.toml/ env before deploy; optional keys list defaults. Version bumps follow SemVer inpyproject.tomlso hosts can judge impact.
Testing in host projects
Use the core-framework[testing] optional extra in the host’s dev or test dependency group so pytest gets testcontainers, pytest-xdist, asgi-lifespan, and a compatible pytest. The package registers a pytest plugin automatically; you do not need pytest_plugins = (...) for core_framework.testing.
- Add the extra (example with
uv): inpyproject.toml, e.g.core-framework = { path = "…", extras = ["testing"] }orcore-framework[testing]in[dependency-groups].dev. - In the host’s root
tests/conftest.py, implementpytest_core_framework_config()returningTestConfigfromcore_framework.testing— passsettings_loaderandapp_factory(usually yourload_default_settingsandinit_app). Optionally setalembic_root,firebase_project_id,include_arq_fixtures, etc. - In the same
conftest.py, define a session-scopedanyio_backendfixture that returns"asyncio"(required so session-scoped async fixtures work with anyio’s pytest integration).
Minimal shape (adjust paths and flags to your host):
from pathlib import Path
import pytest
from core_framework.testing import TestConfig
from my_host.settings import load_default_settings
from my_host.main import init_app
def pytest_core_framework_config() -> TestConfig:
return TestConfig(
settings_loader=load_default_settings,
app_factory=init_app,
# alembic_root=Path(__file__).resolve().parent.parent / "alembic",
# firebase_project_id="test",
# include_arq_fixtures=False,
)
@pytest.fixture(scope="session")
def anyio_backend() -> str:
return "asyncio"
Stable API and fixture list: Package API — Testing. Design notes (xdist, Firebase hybrid, risks): Testing plugin design.
Commands
make run— run the standalone core app locally.make alembic— run bundled core migrations viacf-alembic.make ruff— lint and format.make ty— type check.make vulture— scan for unused code.make test— run tests with the Firebase auth emulator.
Adding Domains
For a new core domain with its own schema name, use .cursor/skills/add-domain/SKILL.md.
The initial scaffold creates settings, an empty Alembic tree, domain class shells, and bootstrap wiring; migration revisions and ALEMBIC_DOMAINS are added later with real DDL.
TODO
- ETag
- py-spy
- Stale-while-revalidate
- Backpressure - uvicorn settings https://uvicorn.dev/settings/
- Backpressure - route level with semaphore
- https://github.com/rennf93/fastapi-guard
- https://github.com/TypeError/secure
- Outbox pattern
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file core_framework-1.2.0.tar.gz.
File metadata
- Download URL: core_framework-1.2.0.tar.gz
- Upload date:
- Size: 404.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.0 {"installer":{"name":"uv","version":"0.10.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"20.04","id":"focal","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1faf22f5fdf653b63348ccbddfdf0d0cd5ac1cce59accf95eb8bcbf80f853ec0
|
|
| MD5 |
e4f51f826223563a10db33f7920054ba
|
|
| BLAKE2b-256 |
3fa00ac1570c773b277a5807a89571a445382743b62066e5617f747daaaa0ea9
|
File details
Details for the file core_framework-1.2.0-py3-none-any.whl.
File metadata
- Download URL: core_framework-1.2.0-py3-none-any.whl
- Upload date:
- Size: 204.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.0 {"installer":{"name":"uv","version":"0.10.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"20.04","id":"focal","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
88507a859bb20217552c7b62bbe086022bc32d5a5eebe9d4944c3c42d18d847f
|
|
| MD5 |
a515256765e48589deb247c986034552
|
|
| BLAKE2b-256 |
b738207f9c7ce3b2f45e5ce119668b84c51bc60ae5f79a3b257f8c27556d4fcc
|