Metadata-Version: 2.5
Name: core-framework
Version: 6.0.0
Summary: Core framework package (import as core_framework)
Project-URL: Homepage, https://github.com/NepNepFFXIV/core-framework
Project-URL: Repository, https://github.com/NepNepFFXIV/core-framework
License-Expression: MIT
License-File: LICENSE
Requires-Python: >=3.14
Requires-Dist: aiofiles>=25.1.0
Requires-Dist: alembic>=1.20.1
Requires-Dist: arq>=0.28.0
Requires-Dist: asyncer>=0.0.20
Requires-Dist: asyncpg>=0.32.0
Requires-Dist: asyncssh>=2.24.1
Requires-Dist: brotli-asgi>=1.7.0
Requires-Dist: device-detector<6.6,>=6.5.1
Requires-Dist: fastapi[standard]>=0.165.0
Requires-Dist: firebase-admin>=7.8.0
Requires-Dist: httpx2<3,>=2.16.2
Requires-Dist: httpx[http2]>=0.28.1
Requires-Dist: itsdangerous>=2.2.0
Requires-Dist: logfire<6.1,>=6.0.0
Requires-Dist: openai<3.58,>=3.57.0
Requires-Dist: opentelemetry-api<1.46,>=1.45.2
Requires-Dist: opentelemetry-exporter-otlp-proto-http<1.46,>=1.45.2
Requires-Dist: opentelemetry-instrumentation-asyncpg<0.67,>=0.66b2
Requires-Dist: opentelemetry-instrumentation-fastapi<0.67,>=0.66b2
Requires-Dist: opentelemetry-instrumentation-httpx<0.67,>=0.66b2
Requires-Dist: opentelemetry-instrumentation-redis<0.67,>=0.66b2
Requires-Dist: opentelemetry-sdk<1.46,>=1.45.2
Requires-Dist: opentelemetry-semantic-conventions<0.67,>=0.66b2
Requires-Dist: orjson>=3.13.0
Requires-Dist: pillow-heif>=1.8.1
Requires-Dist: pillow>=13.0.0
Requires-Dist: pydantic-ai-slim[anthropic,openai]<3,>=2.71.0
Requires-Dist: pyinstrument>=5.1.3
Requires-Dist: python-ulid>=4.2.0
Requires-Dist: redis[hiredis]<6,>=5.3.0
Requires-Dist: resend[async]>=2.55.0
Requires-Dist: structlog>=26.1.0
Requires-Dist: tenacity>=9.2.1
Provides-Extra: testing
Requires-Dist: asgi-lifespan>=2.1.0; extra == 'testing'
Requires-Dist: blockbuster<1.6,>=1.5.29; extra == 'testing'
Requires-Dist: pytest-xdist>=3.8.0; extra == 'testing'
Requires-Dist: pytest>=9.2.0; extra == 'testing'
Requires-Dist: testcontainers[postgres,redis]<4.14,>=4.13.3; extra == 'testing'
Description-Content-Type: text/markdown

# Core framework

Install from PyPI as **`core-framework`**, import **`core_framework`**. MIT — [LICENSE](LICENSE). [Repository](https://github.com/NepNepFFXIV/core-framework), [PyPI](https://pypi.org/project/core-framework/).

## Documentation

| Doc                                                        | Purpose                                                   |
| ---------------------------------------------------------- | --------------------------------------------------------- |
| [docs/README.md](docs/README.md)                           | Doc map (platform, design, library, domains, deployments) |
| [docs/library/package-api.md](docs/library/package-api.md) | Host import surface and upgrade tables                    |
| [CHANGELOG.md](CHANGELOG.md)                               | Release notes (SemVer)                                    |

## Install

```bash
uv add core-framework
```

Pin hosts to a locked version. On each bump, read **[CHANGELOG.md](CHANGELOG.md)** and the host-upgrade tables in **[package-api.md](docs/library/package-api.md)**.

## Local development

Use **Python 3.14**. Install **uv** and **Docker**.

Tracked **`config.toml`** at the repo root is the local-dev settings file (dummy values; no production secrets). Production renders from **`config.toml.template`** via deploy **`envsubst`** — see [architecture decisions](docs/platform/architecture-decisions.md).

```bash
docker compose -f deploy/app/docker-compose.dev.yaml up -d
uv sync --locked --all-extras --dev
uv run cf-alembic
make run
```

**Firebase:** copy **`firebase_config.example.json`** to **`firebase_config.json`** at the repo root and replace with your Firebase project’s **service account** JSON from the console.

For **`make test`**, install the Firebase CLI (Auth emulator) and keep Docker running for the integration containers. The testing plugin starts, waits for, and stops the emulator itself. On Windows, **`make test`** runs unit tests only, because the integration containers need Docker's Linux engine; **`make test-unit`** forces unit-only on any platform. Stop DB/Redis: **`docker compose -f deploy/app/docker-compose.dev.yaml down`**.

**Pre-commit:** `uv sync --dev` installs **pre-commit**. Enable hooks with **`uv run pre-commit install`** (ruff, mdformat, uv-lock, and other checks in **`.pre-commit-config.yaml`**).

## Hosts

In your host app, load **`Settings`** or a **`Settings`** subclass from **`core_framework.core.settings`**, pass it to **`init_app`** from **`core_framework.main`**, then wire host-specific dependencies and routers. **`init_app`** already runs core exception handlers; host-only types use **`register_exception_handler`**.

```python
from core_framework.main import init_app
from fastapi import FastAPI

from myapp.settings import HostSettings, load_default_settings


def build_app(settings: HostSettings | None = None) -> FastAPI:
    resolved = settings if settings is not None else load_default_settings()
    app = init_app(resolved)

    from myapp.bootstrap import configure_dependencies

    configure_dependencies(runtime=app.state.core_runtime)

    from myapp.api.router import router

    app.include_router(router)
    return app
```

From the host repository root, run **`uv run cf-alembic`**. See [core-framework-migration](docs/library/core-framework-migration.md).

**Worker:** production also runs the ARQ worker (`arq core_framework.worker.main.WorkerSettings`, or a host composition that calls the same startup path). Schedules and tasks: [workers.md](docs/library/workers.md). Composition details: [package-api.md](docs/library/package-api.md) (Default deployment entrypoints).

**Observability:** one backend per process. Under **`[observability]`**, set **`backend`** to **`off`**, **`otlp`**, or **`logfire`** (**`local`** forces **`off`**). **`otlp`** needs **`otlp_endpoint`** outside **`local`**; **`logfire`** needs the **`LOGFIRE_TOKEN`** secret. **`otlp`** stack: **`deploy/observability/`** and [observability-lgtm-setup.md](docs/deployments/guides/setup/observability-lgtm-setup.md). Design: [observability-backend-design.md](docs/design/observability-backend-design.md). Host upgrade table: [package-api.md — observability backend](docs/library/package-api.md).

## Host pytest

In your host repository, add the **`core-framework[testing]`** extra to dev or test dependencies. In **`tests/conftest.py`**, register **`pytest_core_framework_config`** (returns **`TestConfig`**) and a session-scoped **`anyio_backend`** fixture that returns **`"asyncio"`**. The extra also wraps tests with Blockbuster so **`core_framework`** cannot perform stdlib blocking I/O on the asyncio loop.

```python
import pytest

from core_framework.testing import TestConfig

from myapp.settings import load_default_settings


def pytest_core_framework_config() -> TestConfig:
    from myapp.main import build_app

    return TestConfig(
        settings_loader=load_default_settings,
        app_factory=build_app,
    )


@pytest.fixture(scope="session")
def anyio_backend() -> str:
    return "asyncio"
```

See [Package API — Testing](docs/library/package-api.md#testing-pytest-plugin) and [testing plugin design](docs/library/testing-plugin-design.md).
