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.
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file module_typica-0.2.14.tar.gz.
File metadata
- Download URL: module_typica-0.2.14.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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f41223efcc9c3eff67d01d53d95f4202ce694262fb0c40dae9ff1d7c186da5e0
|
|
| MD5 |
3b395063a0609bf3fc30882bbdea5f3a
|
|
| BLAKE2b-256 |
440862ce6e8c041a1316194821c7fb1fb6bfbba79216d3b985b67a6b8b63baa1
|
File details
Details for the file module_typica-0.2.14-py3-none-any.whl.
File metadata
- Download URL: module_typica-0.2.14-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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8678667fd67e382ca3e4966ec1662c0f875bad21429cc31d9260feaa08b7dc67
|
|
| MD5 |
61ee5fd02dad3f8114621bf97feca25f
|
|
| BLAKE2b-256 |
911650fa739450b53802f1a873035df41287ad9904c04fa374d394bbd466f440
|