Skip to main content

Utilidades corporativas para automatización RPA en Python

Project description

util-rpa

Librería de utilidades corporativas en Python orientada a automatización operativa (RPA),
procesos batch, RPA y pipelines backend.

Incluye módulos para:

  • 📧 Envío de correos SMTP
  • 🗄️ Conexión a SQL Server(SQLCMD y BCP)
  • 📜 Configuración de logging centralizado

Diseñado para entornos productivos: scripts backend, ETLs, servicios batch y jobs automatizados.


✨ Objetivos

  • Simplificar tareas repetitivas en proyectos Python empresariales
  • Reducir boilerplate en envío de correos o ejecución SQL
  • Mantener estandarización y buenas prácticas
  • Facilitar adopción por equipos heterogéneos

🚀 Instalación

pip install util-rpa

Requiere Python >= 3.9 y < 3.13


📁 Estructura del paquete

util_rpa/
│
├── mail/
│   ├── smtp_client.py
│   ├── smtp_notifier.py
│
├── sql/
│   ├── sqlcmd.py        # sqlcmd (batch SQL)
│   ├── bcp.py           # BCP (bulk IN/OUT)
│   ├── parsers.py       # parseo de logs SQL
│
├── logging_utils.py
├── __init__.py
└── bin/
    └── mail.exe  (legacy)

✉️ Módulo Mail

Este módulo provee un cliente SMTP estándar y opcionalmente plantillas simples.

Ejemplo: envío básico

from util_rpa.mail.smtp_client import SMTPClient
from util_rpa.mail.smtp_notifier import SMTPNotifier

EMAIL_SUBJECT = "Proceso RPA - ${FECHA}"

EMAIL_BODY = """
<h2>Hola ${USUARIO}</h2>
<p>Este es un test de envío desde util-rpa.</p>
<b>Estado:</b> ${ESTADO}
<br><br>
<small>Mensaje generado automáticamente.</small>
"""

client = SMTPClient()

notifier = SMTPNotifier(
    smtp=client,
    sender="robot.bolo@movistar.com.pe",
    to=["jonathan.bolo@integratel.com.pe"],
    cc=None,
    subject_template=EMAIL_SUBJECT,
    body_template=EMAIL_BODY,
)

resultado = notifier.notify(
    context={
        "FECHA": "2025/01/01",
        "USUARIO": "Jonathan",
        "ESTADO": "✔️ OK",
    }
)
print("Resultado envío normal: success=%s error=%s",
    resultado.success,
    resultado.error,
)

🗄️ Módulo SQL

1️⃣ SQLCMD (batch SQL)

Para scripts .sql complejos:

  • múltiples batches
  • prints
  • :setvar
  • ejecución operacional
from util_rpa.sql.sqlcmd import SQLCmd
from pathlib import Path

sqlcmd = SQLCmd(ctx.secrets.db)

sqlcmd.run(
    sql_file=Path("scripts/proceso.sql"),
    output_log=Path("logs/sqlcmd.log"),
    variables={"${FECHA}": "20250101"}
)

2️⃣ BCP (bulk IN / OUT)

Para cargas y descargas masivas.

from util_rpa.sql.bcp import BCP

bcp = BCP(ctx.secrets.db)
bcp.run(
    table="dbo.tabla",
    file=Path("data/salida.txt"),
    operation="OUT",
    error_log=Path("logs/bcp.err")
)

3️⃣ Parsers (parseo de logs SQL)

Extrae data desde logs generados por sqlcmd o bcp.

from util_rpa.sql.parsers import extract_prefixed_lines

extract_prefixed_lines(
    sql_log=Path("logs/sqlcmd.log"),
    output_file=Path("data/resultado.txt"),
    prefix="DATA:"
)

📝 Logging

Inicializa logger raíz reutilizable.

from util_rpa.logging_utils import init_logging

log = init_logging(
    level="INFO",
    log_file="process.log",
    max_bytes=10*1024*1024,
    backup_count=3
)

Ahora puedes usar:

log.info("Iniciando proceso")
log.error("Error crítico", exc_info=True)

Logging rotativo para procesos batch/cron grandes.


⚠️ Sobre mail.exe (legacy)

util_rpa/bin/mail.exe es un envío SMTP alternativo para entornos Windows sin relay o TLS.

  • Úsalo solo como fallback
  • No recomendado en Linux ni Docker
  • No recomendado en entornos CI/CD

📦 Requerimientos

Dependencias mínimas:

pandas>=2.0,<3.0
python-dateutil>=2.8,<3.0

🏛️ Versionamiento

El paquete sigue Semantic Versioning (SemVer).

  • 2.0.0 → Primera versión modular (breaking changes respecto a 1.x)
  • 2.1.x → Nuevas funcionalidades sin romper compatibilidad
  • 2.1.1 → Hotfix

🧪 Desarrollo

Instalar dependencias de desarrollo:

pip install .[dev]

Correr tests:

pytest -q

📌 Buenas prácticas recomendadas

  • Inicializa logging una sola vez en main.py
  • Usa plantillas para correos en vez de concatenación manual
  • No expongas credenciales en código
  • No uses mail.exe si tienes SMTP normal

📜 Licencia

MIT — Uso libre con atribución.


✉️ Contacto / Autor

  • Jonathan Bolo
  • Especialista en ingeniería, Python, automatización corporativa
  • Integratel Perú

📎 Ejemplos listos para copiar

Puedes crear un script main.py:

from util_rpa.logging_utils import init_logging
from util_rpa.mail.smtp import SMTPClient
from util_rpa.sql.sqlserver import SQLServer

log = init_logging()

# Notificación
smtp = SMTPClient("10.10.10.1", port=25)
smtp.send(...)

🛡️ Disclaimer

util-rpa es una librería técnica. No se recomienda para UI, web frameworks o interfaces HMI. Diseñada para backend operativo, batch y automatización con RPAs.

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

util_rpa-2.1.5.tar.gz (29.6 kB view details)

Uploaded Source

Built Distribution

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

util_rpa-2.1.5-py3-none-any.whl (29.3 kB view details)

Uploaded Python 3

File details

Details for the file util_rpa-2.1.5.tar.gz.

File metadata

  • Download URL: util_rpa-2.1.5.tar.gz
  • Upload date:
  • Size: 29.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.17

File hashes

Hashes for util_rpa-2.1.5.tar.gz
Algorithm Hash digest
SHA256 ad5a9129f3ea238cdc1a48da2c9ea18443536a64329f2b036037ea180607e060
MD5 661341c9db0086fb16e64235bb62b562
BLAKE2b-256 77485a882a34dc8faecb6d422144552c61714e9aaeb1d49fda2809bb468ffdae

See more details on using hashes here.

File details

Details for the file util_rpa-2.1.5-py3-none-any.whl.

File metadata

  • Download URL: util_rpa-2.1.5-py3-none-any.whl
  • Upload date:
  • Size: 29.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.17

File hashes

Hashes for util_rpa-2.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 a8d1c61949f7ba46b50e7ee21e17d21cc00246f53ef0fc758a4f365ff8782880
MD5 d17184a27edbf3ea0384fd22f8eb8074
BLAKE2b-256 f70de1dff6a817f5b8e49cb5898cffbbbbf92b92303022dd97c67a66ff901186

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