TinyDB-based document storage for simple telemetry/logging with readable sync, in-memory async and serialized async modes.
Project description
metricallize
Uma forma simples de armazenar telemetria/logs em “banco de documentos” usando TinyDB, com 3 modos de persistência:
readable_sync: JSON legível (escreve no disco de forma direta)in_memory_async: JSON legível com cache em memória (escreve em batch, no flush/close)serialized_async: arquivo binário/comprimido (mais rápido/menor, escreve em background; exige flush/close)
Instalação
pip install metricallize
Para usar o modo serialized_async (serialização/compressão):
pip install "metricallize[serialized_async]"
Conceitos
- Você cria um
DocumentStorage - Você acessa qualquer table com
storage.db.table("nome") - O decorator
storage.capture(table="...")registra uma “execução” (status/duração/erro) nessa table
Campos automáticos gravados pelo capture:
ts:YYYY-MM-DD HH:MM:SS.xxx(UTC)started_at:YYYY-MM-DD HH:MM:SS.xxx(UTC)finished_at:YYYY-MM-DD HH:MM:SS.xxx(UTC)name:module.qualnameda funçãostatus:okouerrorduration:HH:MM:SSinputs: parâmetros serializados (com limites)output: retorno serializado (com limites)memory_before,memory_after,memory_peak,memory_delta:G.M.K(base 1024, K com 3 dígitos)- Em caso de erro:
exc_type,exc_msg
Path e versionamento (por mês)
Se você passar path como diretório (sem extensão), o arquivo é criado automaticamente em:
<path>/storage/YYYY_MM/day_DD.json (modos legíveis)
<path>/storage/YYYY_MM/day_DD.db (modo serialized)
Você pode controlar o nome base com name="...".
Uso: readable_sync (JSON legível)
from pathlib import Path
from metricallize import DocumentStorage
storage_dir = Path.cwd() / "data"
storage = DocumentStorage(path=storage_dir, mode="readable_sync", name="logger")
logger = storage.db.table("loggers")
logger.insert({"event": "startup"})
Uso: in_memory_async (cache em memória, JSON legível)
from pathlib import Path
from metricallize import DocumentStorage
storage_dir = Path.cwd() / "data"
storage = DocumentStorage(
path=storage_dir,
mode="in_memory_async",
name="trace",
write_cache_size=100_000,
)
trace = storage.db.table("trace")
trace.insert({"event": "step"})
storage.flush()
storage.close()
Uso: serialized_async (binário, assíncrono)
from pathlib import Path
from metricallize import DocumentStorage
storage_dir = Path.cwd() / "data"
storage = DocumentStorage(path=storage_dir, mode="serialized_async", name="trace")
trace = storage.db.table("trace")
trace.insert({"event": "step"})
storage.flush()
storage.close()
Decorator: capture
from pathlib import Path
from metricallize import DocumentStorage
storage = DocumentStorage(path=Path.cwd() / "data", mode="readable_sync")
table_name = "trace"
@storage.capture(table=table_name, capture_memory_mb=True)
def soma(a: int, b: int) -> int:
return a + b
@storage.capture(table=table_name)
def falha() -> None:
raise RuntimeError("boom")
soma(1, 2)
try:
falha()
except RuntimeError:
pass
# Se quiser reduzir overhead:
# @storage.capture(table=table_name, capture_memory_mb=False, capture_inputs=False, capture_output=False)
Publicação (TestPyPI e PyPI)
Build:
python -m pip install --upgrade build twine
python -m build
TestPyPI:
python -m twine upload --repository testpypi dist/*
PyPI:
python -m twine upload dist/*
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 metricallize-0.1.1.tar.gz.
File metadata
- Download URL: metricallize-0.1.1.tar.gz
- Upload date:
- Size: 8.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5db11655b143f1cfa10abf7345cd75d15c5120861861a3653cf90c8736e767c3
|
|
| MD5 |
88a635a37a792da633c47f5fa37c22b1
|
|
| BLAKE2b-256 |
ddbeef58f42520ea5a7ec40f84c3fec04c3467c263a766e58278f5d2da0d8c69
|
File details
Details for the file metricallize-0.1.1-py3-none-any.whl.
File metadata
- Download URL: metricallize-0.1.1-py3-none-any.whl
- Upload date:
- Size: 8.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
be8ef34df3961e94159950b80e9168f301b0276260594fef4a4d894830244bd9
|
|
| MD5 |
97d12e6a4d6112017b9cfaf3d65e0b3b
|
|
| BLAKE2b-256 |
9e63299583adf58074118cb743d06b052d49b515f8c676d8429ccaf3433d0337
|