SDK Python para integrar aplicaciones externas con UTILIA OS
Project description
UTILIA OS SDK para Python
SDK Python para integrar aplicaciones externas con el sistema de soporte de UTILIA OS.
Instalación
pip install utilia-sdk
Uso rápido
Asíncrono (recomendado)
from utilia_sdk import UtiliaSDK, CreateTicketInput, CreateTicketUser, IdentifyUserInput
async with UtiliaSDK(base_url="https://os.utilia.ai/api", api_key="tu-api-key") as sdk:
# Identificar usuario
user = await sdk.users.identify(
IdentifyUserInput(external_id="user-123", email="user@example.com")
)
# Crear ticket
ticket = await sdk.tickets.create(
CreateTicketInput(
user=CreateTicketUser(external_id="user-123"),
title="Problema con facturación",
description="No puedo ver mis facturas del mes pasado...",
)
)
print(ticket.ticket_key) # APP-0001
Síncrono
from utilia_sdk import UtiliaSDKSync, CreateTicketInput, CreateTicketUser
with UtiliaSDKSync(base_url="https://os.utilia.ai/api", api_key="tu-api-key") as sdk:
ticket = sdk.tickets.create(
CreateTicketInput(
user=CreateTicketUser(external_id="user-123"),
title="Problema con facturación",
description="No puedo ver mis facturas del mes pasado...",
)
)
Servicios disponibles
sdk.tickets- Tickets de soporte (crear, listar, mensajes, cerrar, reabrir)sdk.users- Usuarios externos (identificar, listar)sdk.files- Archivos adjuntos (subir, obtener URL, quota)sdk.ai- IA (sugerencias, transcripción)sdk.errors- Errores del sistema (reportar, listar, estadísticas)sdk.budgets- Presupuestos CRM (CRUD, items, secciones, flujo, PDF, IA)sdk.budget_templates- Plantillas de presupuesto reutilizablessdk.budget_comments- Comentarios de presupuesto con visibilidadINTERNAL/CLIENTsdk.budget_signatures- Firma electrónica, magic links y certificado legalsdk.organization_settings- Configuración pública de la organización
Comentarios y firmas de presupuestos
Desde la versión 2.1.0 el SDK cubre los dos dominios centrales del flujo de aprobación de presupuestos.
Comentarios (async)
from utilia_sdk import (
UtiliaSDK,
CreateBudgetCommentInput,
BudgetCommentVisibility,
ListBudgetCommentsFilter,
)
async with UtiliaSDK(base_url="https://os.utilia.ai/api", api_key="tu-api-key") as sdk:
# Listar comentarios del cliente
page = await sdk.budget_comments.list(
budget_id,
ListBudgetCommentsFilter(visibility=BudgetCommentVisibility.CLIENT, page=1, limit=20),
)
# Crear un comentario interno con menciones
comment = await sdk.budget_comments.create(
budget_id,
CreateBudgetCommentInput(
body="Revisar el descuento del item 2 antes de enviar.",
visibility=BudgetCommentVisibility.INTERNAL,
mentioned_user_ids=["6d1a4c6b-3f8b-4a0e-a0d1-b29f1f1c21cb"],
),
)
Firmas y magic link (async)
from utilia_sdk import UtiliaSDK, SigningLinkRequest
async with UtiliaSDK(base_url="https://os.utilia.ai/api", api_key="tu-api-key") as sdk:
# Emitir magic link (idempotente por email)
link = await sdk.budget_signatures.generate_signing_link(
budget_id,
SigningLinkRequest(
signer_email="cliente@empresa.com",
signer_name="María García",
expires_in_hours=72,
send_email=True,
),
)
if not link.reused and link.signing_url:
print("Enviar al cliente:", link.signing_url)
# Listar, verificar y certificar
signatures = await sdk.budget_signatures.list(budget_id)
verification = await sdk.budget_signatures.verify(budget_id, signatures[0].id)
if not verification.valid:
print("El documento ha cambiado después de la firma")
pdf_bytes = await sdk.budget_signatures.download_certificate(
budget_id, signatures[0].id
)
Variantes síncronas
Todas las operaciones están disponibles también en UtiliaSDKSync:
from utilia_sdk import UtiliaSDKSync, SigningLinkRequest
with UtiliaSDKSync(base_url="https://os.utilia.ai/api", api_key="tu-api-key") as sdk:
link = sdk.budget_signatures.generate_signing_link(
budget_id,
SigningLinkRequest(signer_email="cliente@empresa.com"),
)
Actualizaciones en tiempo real (SSE)
Recibe notificaciones cuando un agente responde, cambia el estado, resuelve o cierra un ticket:
Asíncrono
async with UtiliaSDK(base_url="https://os.utilia.ai/api", api_key="tu-api-key") as sdk:
async for event in sdk.tickets.stream_updates(user_id="user-123"):
print(f"Ticket {event['ticketKey']} actualizado: {event['type']}")
# event['type']: 'comment-added' | 'status-changed'
Síncrono
with UtiliaSDKSync(base_url="https://os.utilia.ai/api", api_key="tu-api-key") as sdk:
for event in sdk.tickets.stream_updates(user_id="user-123"):
print(f"Ticket {event['ticketKey']} actualizado: {event['type']}")
Reportar errores del sistema
import traceback
from utilia_sdk import UtiliaSDK, ReportErrorInput
async with UtiliaSDK(base_url="https://os.utilia.ai/api", api_key="tu-api-key") as sdk:
try:
await procesar_pago(orden)
except Exception as e:
result = await sdk.errors.report(ReportErrorInput(
message=str(e),
module="pagos",
severity="critical",
stack=traceback.format_exc(),
endpoint="/api/payments",
method="POST",
))
print(result.hash) # Hash de deduplicación
print(result.deduplicated) # True si ya existía
OAuth y Sign In
Desde la versión 0.5.0, el SDK incluye soporte nativo para OAuth 2.1 con PKCE:
from utilia_sdk import UtiliaSDK
sdk = UtiliaSDK(
base_url="https://os.utilia.ai/api",
oauth={
"client_id": "client_xxxxxxxxxx",
"redirect_uri": "http://localhost:8000/callback",
"scopes": ["openid", "profile", "email"],
},
)
# Generar URL de autorización
auth_url = await sdk.oauth.get_authorization_url()
# Opcionalmente, solicitar un tema específico para la pantalla de consentimiento
dark_url = await sdk.oauth.get_authorization_url(theme="dark")
# Manejar callback
tokens = await sdk.oauth.handle_callback(code)
user_info = sdk.oauth.get_user_info()
Documentación completa: https://os.utilia.ai/dashboard/docs/integraciones-sdk/sdk-python-guia-oauth
Manejo de errores
from utilia_sdk import UtiliaSDKError, ErrorCode
try:
ticket = await sdk.tickets.create(data)
except UtiliaSDKError as e:
if e.is_unauthorized:
print("API Key inválida")
elif e.is_rate_limited:
print("Demasiadas peticiones")
elif e.is_retryable:
print("Error temporal, reintentar")
else:
print(f"Error: {e.code} - {e.message}")
Licencia
MIT
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 utilia_sdk-2.1.0.tar.gz.
File metadata
- Download URL: utilia_sdk-2.1.0.tar.gz
- Upload date:
- Size: 67.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ee8ef247ada76b681fd3b8705c99834670449d23f67fdfb8ccf3a83c826e0015
|
|
| MD5 |
7a36af52a16e5e1de80328790984b110
|
|
| BLAKE2b-256 |
fa4dde8ace722da4ad58f263a0003e4aeebef3e09fde5c4e48cf5b5e7ef6842e
|
Provenance
The following attestation bundles were made for utilia_sdk-2.1.0.tar.gz:
Publisher:
sdk-publish.yml on Utilia-ai/UTILIA-OS
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
utilia_sdk-2.1.0.tar.gz -
Subject digest:
ee8ef247ada76b681fd3b8705c99834670449d23f67fdfb8ccf3a83c826e0015 - Sigstore transparency entry: 1339620692
- Sigstore integration time:
-
Permalink:
Utilia-ai/UTILIA-OS@7cbad461ca165cb6858b39ae189a0a026a244d61 -
Branch / Tag:
refs/tags/sdk-python@2.1.0 - Owner: https://github.com/Utilia-ai
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
sdk-publish.yml@7cbad461ca165cb6858b39ae189a0a026a244d61 -
Trigger Event:
push
-
Statement type:
File details
Details for the file utilia_sdk-2.1.0-py3-none-any.whl.
File metadata
- Download URL: utilia_sdk-2.1.0-py3-none-any.whl
- Upload date:
- Size: 69.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
06a9b4c89608bdb188d47fab65e91215bf514ab7350d598a70022a84cafe5c44
|
|
| MD5 |
65c2f50b4b19cae9e17109204f2df7ec
|
|
| BLAKE2b-256 |
91d09b5071c0f599dfe14be082805106b02ce200bcf5297563c5503a1712a871
|
Provenance
The following attestation bundles were made for utilia_sdk-2.1.0-py3-none-any.whl:
Publisher:
sdk-publish.yml on Utilia-ai/UTILIA-OS
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
utilia_sdk-2.1.0-py3-none-any.whl -
Subject digest:
06a9b4c89608bdb188d47fab65e91215bf514ab7350d598a70022a84cafe5c44 - Sigstore transparency entry: 1339620697
- Sigstore integration time:
-
Permalink:
Utilia-ai/UTILIA-OS@7cbad461ca165cb6858b39ae189a0a026a244d61 -
Branch / Tag:
refs/tags/sdk-python@2.1.0 - Owner: https://github.com/Utilia-ai
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
sdk-publish.yml@7cbad461ca165cb6858b39ae189a0a026a244d61 -
Trigger Event:
push
-
Statement type: