Skip to main content

Backend-agnostic domain model, service layer, authorization, query AST and DTOs for varco

Project description

varco-core

PyPI version Python License: Apache 2.0 GitHub

Backend-agnostic domain model and service layer for varco.

Provides the pure-Python building blocks that all backend packages depend on — no ORM imports at the core layer. Pair it with varco-sa (SQLAlchemy) or varco-beanie (MongoDB) for a concrete backend.


Install

pip install varco-core

Features

  • Domain modelDomainModel, AuditedDomainModel, VersionedDomainModel, soft-delete and multi-tenant variants
  • Generic async serviceAsyncService with built-in create / read / update / delete / list, pagination, soft-delete, and multi-tenancy mixins
  • AuthorizationAbstractAuthorizer, GrantBasedAuthorizer, RoleBasedAuthorizer, OwnershipAuthorizer
  • DTO layerCreateDTO, ReadDTO, UpdateDTO, generate_dtos() factory, cursor-based pagination
  • Fluent query builderQueryBuilder → AST → QueryParser (string → AST via Lark grammar); backend-independent
  • JWT / JWKJwtBuilder, JwtParser, JwkBuilder, MultiKeyAuthority, OIDC + PEM sources
  • Tracingcorrelation_context, current_correlation_id, CorrelationIdFilter
  • DI-ready — all service classes are designed for constructor injection via providify

What's in the package

Module Purpose
model.py DomainModel, AuditedDomainModel, VersionedDomainModel, SoftDeleteMixin, TenantMixin and derived classes
meta.py FieldHint, ForeignKey, PrimaryKey, PKStrategy, constraints, pk_field()
mapper.py AbstractMapper — bidirectional ORM ↔ domain translation
repository.py AsyncRepository ABC — CRUD + exists() + stream_by_query()
uow.py AsyncUnitOfWork ABC
registry.py DomainModelRegistry + @register decorator
providers.py RepositoryProvider ABC
assembler.py AbstractDTOAssembler[D, C, R, U]
service/base.py AsyncService, IUoWProvider
service/tenant.py TenantAwareService, TenantUoWProvider, tenant_context
service/soft_delete.py SoftDeleteService
service/types.py Assembler alias, ServiceProtocol
auth/ AbstractAuthorizer, Action, AuthContext, ResourceGrant
auth/helpers.py GrantBasedAuthorizer, OwnershipAuthorizer, RoleBasedAuthorizer
exception/ FastrestErrorCodes, ErrorCode, ErrorMessage, HTTP error mapping
tracing.py correlation_context, current_correlation_id, CorrelationIdFilter
query/ QueryBuilder, QueryParams, QueryParser, AST visitors
jwt/ JwtBuilder, JwtParser, JwtUtil, JsonWebToken
jwk/ JwkBuilder, JsonWebKey, JsonWebKeySet
authority/ JwtAuthority, MultiKeyAuthority, TrustedIssuerRegistry, OIDC/PEM sources

Quick start

Define a domain model

from __future__ import annotations
from typing import Annotated
from varco_core import AuditedDomainModel
from varco_core.meta import FieldHint, PrimaryKey, PKStrategy, pk_field

class Post(AuditedDomainModel):
    pk: Annotated[int, PrimaryKey(PKStrategy.INT_AUTO)] = pk_field()
    title: Annotated[str, FieldHint(max_length=200)]
    body: str
    published: bool = False

Wire a service with DI

from varco_core import AsyncService, IUoWProvider
from varco_core.assembler import AbstractDTOAssembler
from varco_core.auth import AbstractAuthorizer
from providify import Inject, Singleton

@Singleton
class PostService(AsyncService[Post, int, CreatePostDTO, PostReadDTO, UpdatePostDTO]):
    def __init__(
        self,
        uow_provider: Inject[IUoWProvider],
        authorizer:   Inject[AbstractAuthorizer],
        assembler:    Inject[AbstractDTOAssembler[Post, CreatePostDTO, PostReadDTO, UpdatePostDTO]],
    ) -> None:
        super().__init__(uow_provider=uow_provider, authorizer=authorizer, assembler=assembler)

    def _get_repo(self, uow): return uow.posts

Build and run a query

from varco_core import QueryBuilder, QueryParams

params = QueryParams(
    node=QueryBuilder().eq("published", True).and_().gt("pk", 10).build(),
    limit=20,
    offset=0,
)

# Parse from a query string (e.g. from a URL parameter)
from varco_core import QueryParser
params = QueryParser().parse('published == true AND pk > 10', limit=20)

JWT — build and verify tokens

from varco_core import JwtBuilder, JwtParser

token = JwtBuilder(secret="s3cr3t").subject("user-42").expires_in(3600).build()
payload = JwtParser(secret="s3cr3t").parse(token)

Related packages

Package Description
varco-sa SQLAlchemy async backend
varco-beanie Beanie / Motor MongoDB backend

Links

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

varco_core-0.0.2.tar.gz (165.0 kB view details)

Uploaded Source

Built Distribution

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

varco_core-0.0.2-py3-none-any.whl (212.0 kB view details)

Uploaded Python 3

File details

Details for the file varco_core-0.0.2.tar.gz.

File metadata

  • Download URL: varco_core-0.0.2.tar.gz
  • Upload date:
  • Size: 165.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.2.1 CPython/3.11.11 Linux/6.6.87.2-microsoft-standard-WSL2

File hashes

Hashes for varco_core-0.0.2.tar.gz
Algorithm Hash digest
SHA256 ffec043405327e82ce543a29a577e8f87431d27e50805a6ef3963ed733e735e5
MD5 2d0d40a8b06678f7ff1003899eaa3d28
BLAKE2b-256 b91a8b39f0e472bc731c6ba6ec84886a262798912e42e2d00bba03ddd7d38c34

See more details on using hashes here.

File details

Details for the file varco_core-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: varco_core-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 212.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.2.1 CPython/3.11.11 Linux/6.6.87.2-microsoft-standard-WSL2

File hashes

Hashes for varco_core-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 f82606ffc1fa8a23a6f652fc8a33012b01a0b0c2d3f316277dd4d3c06ae7f42c
MD5 7c951f2f2714f735067c8e54bc3f78ff
BLAKE2b-256 496e0dbafa64607fb584ecee01277c96b877fd3c9b14f8606d3acdb400609123

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