Skip to main content

Standard Pydantic usages & utilities

Project description

module-typica

Standardized Pydantic models and utilities for the things every service re-writes: database/queue connection metadata, request and response schemas, identifiers, enums, logging, and optional ready-made connectors. Define once, validate everywhere.

PyPI

Install

pip install module-typica

The core package is pure Pydantic. The connectors under typica.modules need extra drivers — install only the ones you use:

pip install module-typica psycopg[binary,pool] shapely python-dateutil  # postgres
pip install module-typica pymongo            # mongo
pip install module-typica redis              # redis
pip install module-typica clickhouse-connect # clickhouse
pip install module-typica confluent-kafka    # kafka
pip install module-typica pika               # rabbitmq
pip install module-typica elasticsearch7 elasticsearch8  # elasticsearch

Usage

Connection metadata

Alias-rich models that accept whatever shape your config arrives in (snake_case, camelCase, common synonyms) and parse connection URIs.

from typica import DBConnectionMeta

# From a URI...
meta = DBConnectionMeta(uri="postgresql://user:pass@localhost:5432/mydb")
meta.host       # "localhost"
meta.port       # 5432
meta.database   # "mydb"

# ...or from parts, then build a URI:
meta = DBConnectionMeta(host="localhost", port=5432, username="user", password="pass", database="mydb")
meta.uri_string(base="postgresql")  # "postgresql://user:pass@localhost:5432/mydb"

# Aliases just work:
DBConnectionMeta.model_validate({"hostname": "db", "db_name": "shop"})

Available: EndpointMeta, AuthMeta, DBConnectionMeta, ClusterConnectionMeta, ESConnectionMeta, S3ConnectionMeta, RedisConnectionMeta, RMQConnectionMeta, KafkaMeta, FileConnectionMeta, DatasetMeta.

Identifiers & metadata mixins

from typica import StringIdentifier, UUIDIdentifier, CreationMeta

class User(StringIdentifier, CreationMeta):
    name: str

u = User(name="ada")
u.id          # auto uuid4 string
u.created_at  # datetime (accepts epoch sec/ms or ISO strings on input)

Mongo _id variants (StringIdentifier_, UUIDIdentifier_) alias the field to _id.

Request / response schemas

from typica import PaginationSchema, FilterOpsSchema
from typica.response import ServiceResponse
from pydantic import BaseModel

PaginationSchema(page=2, size=20)
FilterOpsSchema(filter_by="age", filter_op="gte", filter_value=18)

class UserOut(BaseModel):
    id: str
    name: str

# FastAPI-style OpenAPI response maps:
responses = ServiceResponse(UserOut).get("UserGet", auth=True)
# -> {200, 400, 401, 404, 500} with generated models

Enums

from typica.utils import DataStatus
from typica.utils.enums import Operator

Operator.gte.value        # "gte"
Operator.gte.description  # "value is greater equals to"
DataStatus.list()         # ["active", "archive", ...]

Logging

from typica.utils.log import setup_logger, CustomLogLevel

log = setup_logger("my_app", console_level=CustomLogLevel.INFO)
log.connection("connected")  # custom CONNECTION / SUCCESS levels
log.success("done")

Connectors (optional)

Thin, typed wrappers driven by the connection metadata above. Each is a context manager. Install the matching driver first (see Install).

from typica import RMQConnectionMeta
from typica.modules.rmq import RMQConnector

meta = RMQConnectionMeta(host="localhost", port=5672, exchange="events", routing_key="user.created")
with RMQConnector(meta) as rmq:
    rmq.setup_producer()
    rmq.produce({"id": 1, "name": "ada"})
from typica import ESConnectionMeta
from typica.modules.elastic import ESConnector

with ESConnector(ESConnectionMeta(host="localhost", port=9200)) as es:
    if es.is_healthy():
        for hit in es.scan("users", body={"query": {"match_all": {}}}):
            ...

Also available: typica.modules.psycopg.PsycopgConnector (ingestion engine), typica.modules.ckafka.KafkaConnector, typica.modules.pmongo.MongoConnector, typica.modules.redis.RedisConnector / AsyncRedisConnector, typica.modules.cclickhouse.CHConnector.

Contributors

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

module_typica-0.2.13.tar.gz (37.4 kB view details)

Uploaded Source

Built Distribution

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

module_typica-0.2.13-py3-none-any.whl (44.1 kB view details)

Uploaded Python 3

File details

Details for the file module_typica-0.2.13.tar.gz.

File metadata

  • Download URL: module_typica-0.2.13.tar.gz
  • Upload date:
  • Size: 37.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.3.2 CPython/3.14.3 Linux/6.18.18-1-MANJARO

File hashes

Hashes for module_typica-0.2.13.tar.gz
Algorithm Hash digest
SHA256 39d65180f96becbce4b0333b52525a2e72accb33ab74f2877619dc7812d7c890
MD5 8e12fcd14e03948c05a7fc3c9328f6ba
BLAKE2b-256 55f1a0012a85d525835d27e770633721626c29122276b51c3229c36524e3e14c

See more details on using hashes here.

File details

Details for the file module_typica-0.2.13-py3-none-any.whl.

File metadata

  • Download URL: module_typica-0.2.13-py3-none-any.whl
  • Upload date:
  • Size: 44.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.3.2 CPython/3.14.3 Linux/6.18.18-1-MANJARO

File hashes

Hashes for module_typica-0.2.13-py3-none-any.whl
Algorithm Hash digest
SHA256 c311fd7475b4c311f181f77053be6e23c5ff196be3cbf43a78a74b7fbd2aa0cc
MD5 58adadb55d79566f4129408fb31b90e1
BLAKE2b-256 ed9a38a7e1a44d7daa579cd92830af212abf62d5cbb94dbb15724615220aee31

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