RUC/DNI lookup con proveedores pluggables para Facturación Electrónica Perú
Project description
xfep-lookup
Cliente async para consulta de RUC y DNI con arquitectura de proveedores pluggables — Perú.
Parte del ecosistema XFEP. Permite consultar información tributaria (RUC → SUNAT) y de identidad (DNI → RENIEC) a través de múltiples proveedores intercambiables.
Instalación
pip install xfep-lookup
Uso
import asyncio
from xfep.lookup import RucLookup, DniLookup
from xfep.lookup.providers import ApisNet
async def main():
provider = ApisNet(token="tu_token")
# Consulta RUC
ruc = RucLookup(provider=provider)
info = await ruc.get("20123456789")
print(info.razon_social, info.estado, info.condicion)
# Consulta DNI
dni = DniLookup(provider=provider)
persona = await dni.get("12345678")
print(persona.nombres, persona.apellido_paterno)
asyncio.run(main())
Proveedores built-in
| Provider | Endpoint | Notas |
|---|---|---|
ApisNet |
apis.net.pe | Token requerido |
ApiInti |
apiperu.dev | Token requerido |
PadronSunat |
CSV local | Consulta offline del padrón descargado |
Características
- Arquitectura pluggable — Cambiá el proveedor sin cambiar el código cliente.
- Proveedores built-in — Soporte para APIs.net.pe, SUNAT directa, RENIEC directa (según proveedor).
- Excepciones tipadas —
NotFoundError,ProviderError,LookupError. - 100% async/await — Construido sobre
httpx.AsyncClient. - Context manager — Gestión automática del ciclo de vida del cliente HTTP.
API
RucLookup(provider)
from xfep.lookup import RucLookup
from xfep.lookup.providers import ApisNet
lookup = RucLookup(provider=ApisNet(token="..."))
info: RucInfo = await lookup.get("20123456789")
Retorna RucInfo con: ruc, razon_social, nombre_comercial, estado, condicion, direccion, ubigeo, etc.
DniLookup(provider)
from xfep.lookup import DniLookup
from xfep.lookup.providers import ApisNet
lookup = DniLookup(provider=ApisNet(token="..."))
info: DniInfo = await lookup.get("12345678")
Retorna DniInfo con: dni, nombres, apellido_paterno, apellido_materno, nombre_completo.
Implementar un proveedor custom
from xfep.lookup import LookupProvider, RucInfo
class MiProveedor(LookupProvider):
async def query_ruc(self, ruc: str) -> RucInfo:
# ... tu lógica
pass
Excepciones
NotFoundError— Documento no existe en el registro.ProviderError— Error del proveedor externo (5xx, timeout, etc.).LookupError— Excepción base.
Stack
- Python >= 3.13
- httpx >= 0.27
- Build: Hatchling
- Tests: pytest + pytest-asyncio
Desarrollo
git clone https://github.com/Xpertik/xfep-lookup.git
cd xfep-lookup
python3.13 -m venv .venv
source .venv/bin/activate
pip install -e ".[dev]"
pytest -v
Licencia
Apache License 2.0 — 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 xfep_lookup-0.1.0.tar.gz.
File metadata
- Download URL: xfep_lookup-0.1.0.tar.gz
- Upload date:
- Size: 14.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6faa31da36a535abb7f4046e434aa389ba5fd74a70b6770e2d6cd1efe79644c3
|
|
| MD5 |
a5103fd560717c02b21f4e71ceb0d77f
|
|
| BLAKE2b-256 |
d3a40ed08875d9085af9024191231af3072cfe221c564426b800eb6a8b62c2ce
|
File details
Details for the file xfep_lookup-0.1.0-py3-none-any.whl.
File metadata
- Download URL: xfep_lookup-0.1.0-py3-none-any.whl
- Upload date:
- Size: 13.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c6a753c63bca4d9b6741f95f53e18c845c87bb97ce546273bc7b9a31a8a91606
|
|
| MD5 |
9b452ccaf691d5d73a381a5d6065fec5
|
|
| BLAKE2b-256 |
609a5f86d82336fc70bceb502bb438349f3bf19629e9e426f60d3bc8d4b5ba6e
|