Skip to main content

TinyDB-based document storage for simple telemetry/logging with sync, cached 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)
  • name: module.qualname da função
  • status: ok ou error
  • duration: HH:MM:SS
  • 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)
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

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

metricallize-0.1.0.tar.gz (6.6 kB view details)

Uploaded Source

Built Distribution

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

metricallize-0.1.0-py3-none-any.whl (6.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: metricallize-0.1.0.tar.gz
  • Upload date:
  • Size: 6.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for metricallize-0.1.0.tar.gz
Algorithm Hash digest
SHA256 bbfe1e14fefbc1a2faffe8278d37a321e02a1998b996e0702a50efb6a201713e
MD5 798c35885864ee388e85321ffbce61b6
BLAKE2b-256 864293f5e597f69a28fd27643b73e869b2f4a86aa1e550273202b61a7f11c686

See more details on using hashes here.

File details

Details for the file metricallize-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: metricallize-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 6.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for metricallize-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 85f654c44df5850410758f6d20d1971b0440e7a973246d3ca1ff5fd17c8e21cd
MD5 6d5ae46113fb1f69837ae83e18a9077f
BLAKE2b-256 bf9687dd7def101e7e401fe021d50bc106a5b85ea9cba9776b2b82e554f1a60e

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