Skip to main content

Vanty App framework: AppConfig + AppRegistry, typed event bus, ULID Tortoise base models, security middleware, TaskIQ broker factory.

Project description

vanty-core

Shared base models, ULID fields, security middleware, and TaskIQ integration for the Vanty ecosystem.

Installation

pip install vanty-core

With optional dependencies:

# Auth integration (organization scoping, task context)
pip install vanty-core[auth]

# TaskIQ background tasks with auth context propagation
pip install vanty-core[taskiq]

# Everything
pip install vanty-core[all]

ULID Primary Keys

All base models use ULID primary keys – 128-bit identifiers that are lexicographically sortable by creation time. Stored as native UUID columns in the database.

from vanty_core.db.models import TimestampedModel
from tortoise import fields

class Product(TimestampedModel):
    name = fields.CharField(max_length=255)

    class Meta:
        table = "product"

Records are automatically assigned time-ordered IDs and can be sorted by id for chronological ordering.

Organization-Scoped Models

Models that belong to a tenant automatically filter queries based on the active AuthContext from vanty-auth:

from vanty_core.db.models import OrganizationScopedModel
from tortoise import fields

class Project(OrganizationScopedModel):
    name = fields.CharField(max_length=255)

    class Meta:
        table = "project"

# Automatically filtered to current organization
projects = await Project.filter(name__icontains="demo")

# Bypass scoping for admin operations
all_projects = await Project.unscoped.all()

If no AuthContext is active, scoped queries return empty results (fail-closed).

Security Middleware

Scanner Blocker

Blocks common vulnerability scanner paths at the ASGI level:

from vanty_core.security.middleware import SecurityScannerBlockerMiddleware

app.add_middleware(SecurityScannerBlockerMiddleware)

Rate Limiting

Factory for slowapi with in-memory, Redis, or Memcached backends:

from vanty_core.security.rate_limit import create_limiter
from slowapi import _rate_limit_exceeded_handler
from slowapi.errors import RateLimitExceeded

limiter = create_limiter(storage_uri="redis://localhost:6379")
app.state.limiter = limiter
app.add_exception_handler(RateLimitExceeded, _rate_limit_exceeded_handler)

@router.post("/submit")
@limiter.limit("10/minute")
async def submit(request: Request):
    ...

TaskIQ Integration

Propagate auth context into background tasks:

from vanty_core.tasks.broker import create_broker
from vanty_core.tasks.middleware import AuthContextTaskMiddleware
from vanty_core.tasks.context import send_with_context

broker = create_broker()
broker.add_middlewares([AuthContextTaskMiddleware(auth_context_service)])

@broker.task
async def process_order(order_id: str):
    # AuthContext is available here via asgiref.local
    ...

# Send with current auth context attached
await send_with_context(process_order, order_id="123")

Development

uv sync --dev
uv run pytest -q
uv run ruff check

Releasing

Tags trigger the release workflow. The GitHub Actions pipeline builds, creates a GitHub release, and publishes to PyPI automatically.

git tag v0.1.0
git push origin v0.1.0

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

vanty_core-0.3.0.tar.gz (93.3 kB view details)

Uploaded Source

Built Distribution

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

vanty_core-0.3.0-py3-none-any.whl (20.7 kB view details)

Uploaded Python 3

File details

Details for the file vanty_core-0.3.0.tar.gz.

File metadata

  • Download URL: vanty_core-0.3.0.tar.gz
  • Upload date:
  • Size: 93.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for vanty_core-0.3.0.tar.gz
Algorithm Hash digest
SHA256 840c19db8f62cded7593d9a9933b8e033fa3a37d2597170f1b1645e001016360
MD5 705ffeb6890b2f600627d6234f699340
BLAKE2b-256 10c04212143bc7280d2645fd8ba0f56bbd12b794e53ce19ef49e7c6ac301e7c7

See more details on using hashes here.

Provenance

The following attestation bundles were made for vanty_core-0.3.0.tar.gz:

Publisher: release.yml on advantch/vanty-core

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file vanty_core-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: vanty_core-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 20.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for vanty_core-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9f1fb7aa30ab6baf05eeaae50100f1eb8d64fefdb0d51084516e2b3c5a6285bc
MD5 9d78dac3ac61c3854b45829ca8c59ddf
BLAKE2b-256 cf450e05cc1ca0cb2ce03effd44873c241c8d9c851c99c7b34f4fbc9fbc15e9b

See more details on using hashes here.

Provenance

The following attestation bundles were made for vanty_core-0.3.0-py3-none-any.whl:

Publisher: release.yml on advantch/vanty-core

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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