Skip to main content

Shared async PostgreSQL (asyncpg + SQLAlchemy 2) and Redis primitives for the ForkTex ecosystem

Project description

forktex-core

PyPI Python License

Shared async PostgreSQL (asyncpg + SQLAlchemy 2) and Redis primitives for the ForkTex ecosystem.

forktex-core is the foundation library every ForkTex Python service depends on. It owns the async SQLAlchemy engine, session helpers, ORM mixins, and Redis caching primitives, so individual services don't reinvent connection management.

Install

pip install forktex-core

PostgreSQL (asyncpg + SQLAlchemy 2) and Redis (hiredis) are both included by default — no optional extras to remember. Requires Python 3.12+.

Quick Start

PostgreSQL

from forktex_core.psql import (
    init_engine, close_engine, get_session,
    BaseDBModel, TimestampMixin, AuditMixin,
)

# Initialize once in your app's lifespan
init_engine("postgresql+asyncpg://user:pass@localhost/db")

# Use a session anywhere
async with get_session() as session:
    user = await session.get(User, user_id)

Tunable engine kwargs are passed straight through to create_async_engine:

init_engine(
    "postgresql+asyncpg://user:pass@host/db",
    pool_size=20,
    max_overflow=10,
    pool_pre_ping=True,
)

Redis

from forktex_core.redis import init, close, cached

await init("redis://localhost:6379/0")

@cached(ttl=300)
async def get_profile(user_id: str):
    ...

What's in the package

Module Responsibility
forktex_core.psql.connection init_engine / close_engine / get_session lifecycle
forktex_core.psql.models BaseDBModel, TimestampMixin, AuditMixin
forktex_core.psql.crud Generic async CRUD helpers over SQLAlchemy 2
forktex_core.redis.connection init / close / get_client for the shared Redis pool
forktex_core.redis.ops Typed get / set / delete / incr / mget operations
forktex_core.redis.decorators @cached(ttl=...) for transparent function caching
forktex_core.redis.namespaces Key namespacing helpers

Consumed as a runtime dependency by forktex-cloud-api, forktex-intelligence-api, and any future ForkTex Python service that needs PostgreSQL or Redis.

Configuration

Connection strings and pool settings are passed in by the host service at init_engine / init time — forktex-core does not read environment variables directly. Each consuming service decides its own configuration source (env vars, secrets manager, manifest, etc.).

Development

The root Makefile is generated by forktex fsd makefile sync from forktex.json — do not hand-edit.

make help              # list every available target
make deps              # editable install
make format            # ruff format
make lint              # ruff check
make test              # pytest tests/
make build             # python3 -m build → dist/
make ci                # format-check + lint + license-check + audit + test + build
make clean             # remove caches and dist/

make ci is the single command that gates a publish: it format-checks, lints, verifies dual-license headers across every source file, audits dependencies for known CVEs, runs the test suite, and builds the wheel + sdist with twine check.

make start / make stop / make logs are intentional no-ops — forktex-core is a library, there is nothing to run.

License headers

Every source file carries the AGPL-3.0 + Commercial dual-license SPDX header, applied idempotently via:

make license-check    # CI gate — fails if any source file is missing the header
make license-fix      # add or refresh headers across src/, tests/, scripts/
make license-strip    # remove headers (used before license-model changes)

FSD Self-Description

This repo follows the ForkTex Standard Delivery (FSD) shape:

  • root manifest: forktex.json
  • profile: workspace/python-monorepo
  • target maturity: L3
  • single publishable package: forktex-core at path .

Re-validate locally with:

forktex fsd --project-dir . check
forktex arch discover --project-dir . --output-dir /tmp/arch-corepy

License

Dual-licensed — AGPL-3.0-or-later for open-source use, commercial for everything else (proprietary products, SaaS without source release, redistribution in closed-source form). See LICENSE and NOTICE for the full terms.

Commercial licensing inquiries: info@forktex.com.

The 1.0.0 release on PyPI remains under MIT; from 0.2.3 onwards the package ships AGPL-3.0+Commercial.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

forktex_core-0.2.3.tar.gz (14.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

forktex_core-0.2.3-py3-none-any.whl (22.6 kB view details)

Uploaded Python 3

File details

Details for the file forktex_core-0.2.3.tar.gz.

File metadata

  • Download URL: forktex_core-0.2.3.tar.gz
  • Upload date:
  • Size: 14.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for forktex_core-0.2.3.tar.gz
Algorithm Hash digest
SHA256 1b5dd915604e2f4bc4e842faa3217bb2ef37ac12c5e37f7d115ce0312e9fad90
MD5 69d88ac624c86d051e0571676e6e20f0
BLAKE2b-256 75d2bd44eeadaf3eb463e7af81ef5f35d6a5088229218267ed8235d0fb6e45a5

See more details on using hashes here.

File details

Details for the file forktex_core-0.2.3-py3-none-any.whl.

File metadata

  • Download URL: forktex_core-0.2.3-py3-none-any.whl
  • Upload date:
  • Size: 22.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for forktex_core-0.2.3-py3-none-any.whl
Algorithm Hash digest
SHA256 bb5f5fde9b214d5dc9fafb0a0cb3f02991810d2a8d392839c4daad992331302e
MD5 5089b21438a955f49c50fbb2449cc539
BLAKE2b-256 b37079c2f5303098a7aaa36eb044526fe92fc19e38030c0c8b1f715f8e621b43

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page