Skip to main content

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

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

Publishing

Tags trigger the release workflow:

git tag v0.1.0
git push origin v0.1.0

The GitHub Actions pipeline builds, creates a GitHub release, and publishes to PyPI via trusted publishing (OIDC).

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.1.0.tar.gz (95.9 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.1.0-py3-none-any.whl (7.7 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for vanty_core-0.1.0.tar.gz
Algorithm Hash digest
SHA256 f532fdb0bc7037ce46bf9a3d2adec5f2a9ee463540dabf95b7128cdacb8a31bd
MD5 d5f9b8f1620e2058192d961e3e3b3279
BLAKE2b-256 567d6ac696f62a3a26980dda26cb8e8116e1c27ffcb629eaf1fac9d83a3fa1fb

See more details on using hashes here.

Provenance

The following attestation bundles were made for vanty_core-0.1.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.1.0-py3-none-any.whl.

File metadata

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

File hashes

Hashes for vanty_core-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 64e8e0e1fdb32a251f650127df0eb7ef5f8d0adafd25f71acc63699897a83d54
MD5 c80c8b5ed054a518fed2695e45fb7d40
BLAKE2b-256 f49b4c4f28627992f708b444cc96d29aef44edf5946caf8640619e2b6ce342ff

See more details on using hashes here.

Provenance

The following attestation bundles were made for vanty_core-0.1.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