Skip to main content

SDK de logging resiliente para automacoes Python com fallback local

Project description

tenant-rpa-sdk

SDK Python para automacoes, com foco em logging resiliente para banco de dados e fallback local.

Objetivo

  • Padronizar logs de automacoes em uma tabela de eventos
  • Evitar perda de eventos em indisponibilidade temporaria do DB
  • Fornecer API simples para uso em qualquer automacao Python

Escopo

  • Somente logging (sem lifecycle start/heartbeat/finish)
  • Postgres-only (psycopg)
  • Dedupe por idempotency_key
  • Fallback local em JSONL + reconciliacao por flush_pending()

Instalacao

Desenvolvimento local

cd tenant-rpa-sdk
python -m venv .venv
source .venv/bin/activate
pip install -U pip
pip install -e .[dev]

Consumo em RPAs (producao)

Use versao pinada:

tenant-rpa-sdk==0.1.1

Canal 1 (oficial) - PyPI publico:

pip install tenant-rpa-sdk==0.1.1

Canal 2 - package no GitHub (asset da Release):

pip install "https://github.com/<org>/<repo>/releases/download/tenant-rpa-sdk-v0.1.1/tenant_rpa_sdk-0.1.1-py3-none-any.whl"

Se seu ambiente usa mirror privado, ajuste --index-url/--extra-index-url no pip.

Variaveis de ambiente (exemplo ficticio)

Os nomes abaixo sao apenas ilustrativos e podem ser ajustados no seu ambiente:

  • APP_DB_PRIMARY ou APP_DB_FAILOVER
  • APP_LOG_TABLE (default event_logs)
  • APP_LOG_SOURCE (default automation.app)
  • APP_LOG_FALLBACK_PATH (default /var/log/example-automation/pending_events.jsonl)
  • APP_LOG_FLUSH_ON_START (default true)
  • APP_LOG_DB_TIMEOUT_SECONDS (default 5)
  • APP_LOG_MAX_MESSAGE_CHARS (default 2000)
  • APP_LOG_MAX_METADATA_BYTES (default 32768)

Conexao de banco (exemplo ficticio)

Formato ilustrativo:

postgres,<host>,<port>,<database>,<user>,<password>

Alias encadeado aceito:

APP_DB_PRIMARY=APP_DB_FAILOVER
APP_DB_FAILOVER=postgres,db.example.local,5432,ops_data,svc_logger,***

Se APP_DB_PRIMARY nao existir, use um alias de contingencia.

Uso rapido

from tenant_rpa_sdk import TenantBackendLogger

logger = TenantBackendLogger(
    project_name="demo-project",
    source="automation.order-sync",
    execution_id=123,
    db_alias_env="APP_DB_PRIMARY",
    fallback_path="/tmp/pending_events.jsonl",
    echo_stdout=True,
    flush_on_start=True,
)

logger.info("Processo iniciado", metadata={"step": "bootstrap"})
logger.warning("API lenta", metadata={"latency_ms": 1200})
logger.error("Falha em consulta", metadata={"query_id": "q-09", "token": "redacted"})

result = logger.flush_pending(limit=200)
print(result)

API publica

Classe principal: tenant_rpa_sdk.logger.TenantBackendLogger

Metodos:

  • debug(message, *, event_type="APP", metadata=None, execution_id=None)
  • info(...)
  • warning(...)
  • error(...)
  • critical(...)
  • log(level, message, *, event_type="APP", metadata=None, execution_id=None)
  • bind_execution(execution_id)
  • flush_pending(limit=200) -> dict

Contrato de fallback JSONL

Cada linha contem:

  • idempotency_key
  • created_at
  • payload
  • attempt
  • last_error
  • next_retry_at

Versionamento e release

  • Politica: SemVer estrito (MAJOR.MINOR.PATCH)
  • Tags de release: tenant-rpa-sdk-vX.Y.Z (geradas automaticamente a partir de pyproject.toml)
  • Publicacao automatica no PyPI por GitHub Actions ao criar tag valida
  • Os artefatos .whl e .tar.gz tambem sao anexados na GitHub Release da mesma tag

Consulte:

  • CHANGELOG.md
  • CONTRIBUTING.md
  • docs/versionamento.md
  • docs/release.md
  • docs/uso-em-rpas.md
  • docs/faq.md

Testes

Unitarios:

pytest tests/unit

Integracao (Postgres real, execucao opt-in):

export TENANT_RPA_SDK_INTEGRATION=true
pytest tests/integration

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

tenant_rpa_sdk-0.1.1.tar.gz (11.1 kB view details)

Uploaded Source

Built Distribution

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

tenant_rpa_sdk-0.1.1-py3-none-any.whl (12.1 kB view details)

Uploaded Python 3

File details

Details for the file tenant_rpa_sdk-0.1.1.tar.gz.

File metadata

  • Download URL: tenant_rpa_sdk-0.1.1.tar.gz
  • Upload date:
  • Size: 11.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for tenant_rpa_sdk-0.1.1.tar.gz
Algorithm Hash digest
SHA256 420683bc65b91a10a2f0a8850ec871ca8f6b0d988fd55cd783f40b96a278522e
MD5 1c0cea5689a01dfefdf4cd9c31df9fb9
BLAKE2b-256 e3b10a024319d2d3973c60fd5e82f37ee6d27a6e52a9f849f90c8e01f8f19e93

See more details on using hashes here.

Provenance

The following attestation bundles were made for tenant_rpa_sdk-0.1.1.tar.gz:

Publisher: python-release.yml on tech-ops-ai/tenant-rpa-sdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tenant_rpa_sdk-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: tenant_rpa_sdk-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 12.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for tenant_rpa_sdk-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 861b28bd9ee38870f36d46221b84224964bd9b6cafee83164c5b05f2c16eee63
MD5 1db3ce6154e36e4438969eaf10845c54
BLAKE2b-256 d4b5a9b6415330797c99bf914107bb261397461b1652a5d89b01b75abb93ae5e

See more details on using hashes here.

Provenance

The following attestation bundles were made for tenant_rpa_sdk-0.1.1-py3-none-any.whl:

Publisher: python-release.yml on tech-ops-ai/tenant-rpa-sdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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