Utilidades para Google Sheets, Drive y webhooks de Google Chat.
Project description
soxlib
Utilidades para Google Sheets, Google Drive, webhooks de Google Chat y calendario de operaciones con soporte para pandas y pandasql.
Incluye helpers para leer/escribir hojas, subir archivos a Drive, enviar resultados a Chat y actualizar calendarios históricos de forma incremental.
Instalación
pip install soxlib
Para desarrollo local:
pip install -e ".[dev]"
Requisitos previos
- Python ≥ 3.8
- Credenciales OAuth: coloca
client_secret.jsonycredentials.jsonenscripts/utils/(o pasa una ruta distinta acreate_login). El flujo generarátoken.pickleal primer uso. - Archivo
scripts/utils/directorio.jsoncon la configuración de IDs de Sheets y webhooks. Ejemplo mínimo:
{
"mi_tabla": {
"GOOGLE_SHEET_ID_FUNCIONAL": "1AbcDEFghi...",
"GOOGLE_SHEET_ID_VISTA_0": "",
"FILTRO_VISTA_0": "",
"ARCHIVO": "mi_archivo.csv"
},
"mi_webhook": {
"GOOGLE_SHEET_ID_FUNCIONAL": "https://chat.googleapis.com/v1/spaces/.../messages?key=...&token=..."
}
}
Módulos
Google Sheets / Drive / Chat (soxlib.gsu)
| Función | Descripción |
|---|---|
lee_hoja_datos(nombre, cloud=True) |
Lee una hoja (Google Sheets o CSV local) a DataFrame. |
actualiza_hoja_datos(df, nombre, overwrite=True, cloud=True) |
Escribe un DataFrame en Sheets y vista opcional. |
enviar_dataframe_a_google_chat(df, webhook_name) |
Envía un DataFrame tabulado a un webhook de Google Chat. |
enviar_mensaje_simple_a_google_chat(msg, webhook_name) |
Envía un mensaje de texto plano al webhook. |
sube_archivo(path, mime_type="image/png") |
Sube archivos a Drive y devuelve el ID. |
sox_enviar_imagen_a_google_chat(path, webhook_name) |
Sube imagen a Drive y envía enlace al webhook. |
create_login(client_secret_path=...) |
Crea un cliente de Sheets autenticado. |
gsheets_to_dataframe(...) |
Convierte hojas de Google Sheets a DataFrame. |
get_all_sheets_data(...) |
Obtiene datos de todas las hojas de un Spreadsheet. |
filtrar_dataframe(df, filtros) |
Filtra un DataFrame con condiciones dinámicas. |
guardar_y_subir_gs(df, nombre) |
Guarda como CSV local y sube a Google Sheets. |
imprimir_tabla(df) |
Imprime un DataFrame como tabla formateada. |
estrella_5_picos_ascii() |
Devuelve arte ASCII decorativo. |
Calendario (soxlib.calendar)
| Función | Descripción |
|---|---|
cal_update(table_1, table_2, table_3, ...) |
Actualiza un calendario histórico a partir de datos nuevos, respetando excepciones. |
Core (soxlib.core)
| Función | Descripción |
|---|---|
add(a, b) |
Suma dos números (función base de la biblioteca). |
Ejemplos rápidos
Google Sheets y Chat
from soxlib import (
lee_hoja_datos,
actualiza_hoja_datos,
enviar_dataframe_a_google_chat,
sox_enviar_imagen_a_google_chat,
)
df = lee_hoja_datos("mi_tabla")
df_filtrado = df[df["status"] == "OK"]
actualiza_hoja_datos(df_filtrado, "mi_tabla")
enviar_dataframe_a_google_chat(df_filtrado, "mi_webhook")
sox_enviar_imagen_a_google_chat("imagen.png", "mi_webhook")
Calendario
from soxlib import cal_update
resultado = cal_update(
datos, # DataFrame con ejecuciones (key, fecha, status)
calendario, # DataFrame histórico con columnas de fecha
especialidad, # DataFrame auxiliar (o None)
col_key="JOBNAME",
col_date="RUN DATE",
col_info="STATUS",
month_window=6,
exceptions=["FORK", "RECUP", "INC"],
)
Estructura del proyecto
soxlib/
├── src/soxlib/
│ ├── __init__.py # Exports públicos y versión
│ ├── core.py # Función base (add)
│ ├── gsu.py # Google Sheets, Drive y Chat
│ └── calendar.py # Actualización de calendarios
├── tests/
│ ├── test_core.py # Tests de core
│ ├── test_gsu.py # Tests de gsu
│ └── test_calendar.py # Tests de calendar
├── pyproject.toml
├── README.md
└── LICENSE
Desarrollo
- Crear y activar un entorno virtual.
- Instalar dependencias de desarrollo:
pip install -e ".[dev]"
- Ejecutar pruebas:
pytest
- Construir el paquete:
python -m build
- Publicar en TestPyPI/PyPI:
twine upload dist/*
Licencia
GPLv3+. Ver LICENSE.
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 soxlib-0.1.2.tar.gz.
File metadata
- Download URL: soxlib-0.1.2.tar.gz
- Upload date:
- Size: 32.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4e2449c2eafc0c2813618e14d7139f71d258d86457ad1f887ffac1067f9991f7
|
|
| MD5 |
dae4fe87c6ab4b2e61dae415bd3824f3
|
|
| BLAKE2b-256 |
c9ce935a778ea322e22831faa004759004cd611f0f6a3d5596197fac3a1f4fae
|
File details
Details for the file soxlib-0.1.2-py3-none-any.whl.
File metadata
- Download URL: soxlib-0.1.2-py3-none-any.whl
- Upload date:
- Size: 28.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
653b5aeb6c62fb286d32c5af620e70f33eb902dabaaa25d088f13cea2ff7eb89
|
|
| MD5 |
d834f2e0d0df14216e3818760f97f119
|
|
| BLAKE2b-256 |
97ca4b92120e25cb6695301b1ac40511897166974e3de4ff124ced99d1415aab
|