be5a7b582e
Añade módulo Python con funciones para la API de Metabase en dominio infra. Incluye cliente HTTP, auth, y CRUD de cards, dashboards y users. Proyecto gestionado con uv (pyproject.toml).
47 lines
1.3 KiB
Markdown
47 lines
1.3 KiB
Markdown
---
|
|
name: metabase_auth
|
|
kind: function
|
|
lang: py
|
|
domain: infra
|
|
version: "1.0.0"
|
|
purity: impure
|
|
signature: "def metabase_auth(base_url: str, email: str, password: str) -> MetabaseClient"
|
|
description: "Autentica contra la API de Metabase con email y password. Retorna un MetabaseClient con session token valido por 14 dias. Endpoint: POST /api/session."
|
|
tags: [metabase, auth, session, api, python]
|
|
uses_functions: []
|
|
uses_types: []
|
|
returns: []
|
|
returns_optional: false
|
|
error_type: "error_go_core"
|
|
imports: [httpx]
|
|
tested: false
|
|
tests: []
|
|
test_file_path: ""
|
|
file_path: "python/functions/metabase/client.py"
|
|
---
|
|
|
|
## Ejemplo
|
|
|
|
```python
|
|
from functions.metabase import metabase_auth
|
|
|
|
client = metabase_auth("http://localhost:3000", "admin@example.com", "pass")
|
|
# client listo para usar con todas las funciones CRUD
|
|
|
|
# Alternativa con API key:
|
|
from functions.metabase import MetabaseClient
|
|
client = MetabaseClient("http://localhost:3000", "mb_api_key_xxxxx")
|
|
```
|
|
|
|
## Notas
|
|
|
|
Dos formas de obtener un client:
|
|
- `metabase_auth()`: login con email/password, obtiene session token via POST /api/session
|
|
- `MetabaseClient(base_url, api_key)`: constructor directo con API key (recomendado para automatizacion)
|
|
|
|
El client es un context manager: `with metabase_auth(...) as client:`
|
|
|
|
Errores comunes:
|
|
- 401: credenciales invalidas
|
|
- Rate limiting en intentos fallidos de login
|