Metadata-Version: 2.4
Name: tilde-afip
Version: 0.1.0a1
Summary: SDK oficial de Tilde para Python — facturación electrónica ARCA (ex AFIP) en Argentina. Server-side.
Project-URL: Homepage, https://tildeafip.com
Project-URL: Documentation, https://tildeafip.com/developers
Project-URL: Repository, https://sistemasat-gustavo.visualstudio.com/Tilde/_git/Tilde
Author: Tilde
License: MIT License
        
        Copyright (c) 2026 Tilde
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
License-File: LICENSE
Keywords: afip,arca,argentina,facturacion,invoicing,sdk,tilde
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Typing :: Typed
Requires-Python: >=3.10
Provides-Extra: dev
Requires-Dist: pytest>=8.0; extra == 'dev'
Description-Content-Type: text/markdown

# tilde-afip

SDK oficial de **Tilde** para Python — facturación electrónica **ARCA (ex AFIP)** en Argentina.

> ⚠️ **Server-side / backend-to-backend.** No uses Client Credentials en código que corra en un cliente no confiable. El `client_secret` nunca debe filtrarse.

> Estado: **alpha** (`0.1.0a1`). API sujeta a cambios hasta `1.0.0`.

## Instalación
```bash
pip install tilde-afip
```
Requiere **Python 3.10+**. Sin dependencias de runtime (transport sobre la stdlib).

## Quickstart
```python
from tilde_afip import TildeClient

tilde = TildeClient(
    client_id="...",
    client_secret="...",
    environment="sandbox",        # "production" por default
    scopes=["invoicing:write"],
)

invoice = tilde.invoices.create({ ... }, idempotency_key=my_key)
print(invoice["cae"])
```
El token OAuth2 (client credentials) se obtiene y cachea automáticamente.

## Errores tipados
```python
from tilde_afip import TildeValidationError

try:
    tilde.invoices.create(req, idempotency_key=key)
except TildeValidationError as e:
    print(e.code, e.status, e.retryable, e.correlation_id, e.body.get("errors"))
```
Familias: `TildeValidationError`, `TildeAuthenticationError`, `TildeAuthorizationError`,
`TildeRateLimitError`, `TildeConflictError`, `TildeNotFoundError`, `TildePaymentRequiredError`, `TildeApiError`.

## Webhooks
Verificá con el **raw body**, antes de parsear:
```python
from tilde_afip import construct_event

event = construct_event(
    payload=raw_body,                       # str | bytes, tal cual llegó
    signature_header=request.headers["X-Tilde-Signature"],
    secret=webhook_secret,
)
if event["type"] == "invoice.authorized":
    ...
```
HMAC-SHA256 en tiempo constante, con anti-replay por timestamp.

## Entornos
| Entorno | Base URL |
|---|---|
| `production` | `https://api.tildeafip.com/v1` |
| `sandbox` | `https://sandbox.api.tildeafip.com/v1` |

## Acceso genérico
Cualquier endpoint de la API: `tilde.request("GET", "/cuit-profiles")`. El recurso `invoices`
está tipado como ejemplo; la cobertura tipada completa se generará del contrato.

## Licencia
Ver `LICENSE`.
