extraer-datos-ine (Python)
SDK oficial en Python para la API de OCR para INE de Extraer Datos de INE — extrae CURP, nombre, clave de elector, dirección y todos los campos de una credencial para votar mexicana (INE/IFE) a partir de una imagen, en segundos.
- 🇲🇽 Diseñado para credenciales INE e IFE (todos los modelos).
- 🧩 Cero dependencias. Solo la librería estándar (
urllib). - 🔠 Tipado (
py.typed):IneDatacon los 20 campos y errores tipados. - 🐍 Compatible con Python 3.9+.
📚 Documentación de la API: https://extraerdatosdeine.com/docs 🔑 Consigue una API key con 20 extracciones gratis: https://extraerdatosdeine.com/register
Instalación
pip install extraer-datos-ine
Uso rápido
from extraer_datos_ine import IneExtractorClient
client = IneExtractorClient(api_key="ine_tu_api_key")
with open("ine_frente.jpg", "rb") as f:
front = f.read()
with open("ine_reverso.jpg", "rb") as f: # opcional, para CIC/OCR del reverso
back = f.read()
result = client.extract(front=front, back=back)
print(result.data["curp"]) # 'PEGJ850101HDFRRL09'
print(result.data["claveElector"]) # 'PRGRJN85010109H100'
print(result.tokens_remaining) # 19
Consultar saldo de tokens
print("Tokens disponibles:", client.get_balance())
Formas de enviar la imagen
El método de envío se elige automáticamente según el tipo de front/back.
| Tipo de entrada | Ejemplo | Método HTTP usado |
|---|---|---|
| Binario | bytes / bytearray |
multipart/form-data |
| Base64 | "..." o {"base64": "..."} |
JSON base64 |
| URL | {"url": "https://..."} |
JSON URL (la API descarga la imagen) |
# Binario
client.extract(front=front_bytes, front_mime_type="image/png")
# Base64
client.extract(front={"base64": b64}, back={"base64": back_b64})
# URL HTTPS
client.extract(front={"url": url}, back={"url": back_url})
frontybackdeben ser del mismo tipo: la API no mezcla métodos en una sola petición.
Manejo de errores
from extraer_datos_ine import IneExtractorError
try:
result = client.extract(front=front)
except IneExtractorError as err:
if err.code == "INSUFFICIENT_TOKENS":
print("Sin tokens. Recarga en:", err.enroll_url)
elif err.code == "LOW_IMAGE_QUALITY":
print("Imagen ilegible. Campos faltantes:", err.missing_fields)
else:
print(f"[{err.code}] {err.message}")
Códigos de error
code |
HTTP | Significado |
|---|---|---|
MISSING_API_KEY |
401 | No se envió la API key |
INVALID_API_KEY |
401 | API key inválida o revocada |
MISSING_IMAGE |
400 | Falta la imagen frontal |
INVALID_IMAGE_FORMAT |
400 | Formato no soportado (usa JPEG, PNG o WebP) |
IMAGE_TOO_LARGE |
400 | La imagen excede 10 MB |
INVALID_BASE64 |
400 | Error al decodificar base64 |
INVALID_MULTIPART |
400 | Error al procesar el formulario multipart |
URL_FETCH_FAILED |
400 | No se pudo descargar la imagen de la URL |
URL_INVALID |
400 | URL inválida (debe ser HTTPS) |
URL_BLOCKED |
400 | URL bloqueada por seguridad |
URL_TIMEOUT |
400 | Timeout al descargar la imagen (10 s) |
UNSUPPORTED_CONTENT_TYPE |
415 | Content-Type no soportado |
INSUFFICIENT_TOKENS |
402 | Saldo insuficiente (ver err.enroll_url) |
LOW_IMAGE_QUALITY |
422 | Imagen ilegible (ver err.missing_fields) |
EXTRACTION_FAILED |
500 | Falló la extracción (el token se reembolsa) |
PROCESSING_ERROR |
500 | Error procesando la imagen (token reembolsado) |
INTERNAL_ERROR |
500 | Error interno del servidor |
NETWORK_ERROR |
— | Fallo de red (lado del cliente) |
TIMEOUT |
— | Se superó el timeout del cliente |
Campos extraídos (IneData)
nombre, apellidoPaterno, apellidoMaterno, domicilio, calle, colonia, codigoPostal, municipio, estado, seccion, curp, claveElector, anioRegistro, fechaNacimiento, sexo, vigencia, numeroVertical, ocr, cic, emision.
Los cuatro últimos (numeroVertical, ocr, cic, emision) viven en el reverso: envía también back para obtenerlos.
Configuración del cliente
IneExtractorClient(
api_key="ine_...",
base_url="https://extraerdatosdeine.com/api/v1", # default
timeout=60.0, # segundos
)
Desarrollo
python -m venv .venv && source .venv/bin/activate
pip install -e .
python -m unittest discover -s tests -v
pip install build && python -m build # genera sdist + wheel en dist/
Enlaces
- 🌐 Sitio: https://extraerdatosdeine.com
- 📚 Documentación de la API: https://extraerdatosdeine.com/docs
- 🔑 Crear cuenta (20 extracciones gratis): https://extraerdatosdeine.com/register
- 📦 SDK de JavaScript/TypeScript: https://www.npmjs.com/package/extraer-datos-ine
Licencia
MIT © Extraer Datos de INE
Metadata
Release files for extraer-datos-ine 1.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| extraer_datos_ine-1.0.1.tar.gz | 9.2 kB | With provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| extraer_datos_ine-1.0.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 19.1 kB
Release files / extraer_datos_ine-1.0.1.tar.gz
| Download URL | extraer_datos_ine-1.0.1.tar.gz |
|---|---|
| Size | 9.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
97919e502bc9b4df2cb70bb5638b77233285a39063818bd069750c65c4746e6d
|
|
BLAKE2b-256 checksum How to use checksums |
e6c282fa845d8df1facb7cf89ddddb365c730f4c25b46f9cfe01c5513518129f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 30, 2026.
Transparency logRelease files / extraer_datos_ine-1.0.1-py3-none-any.whl
| Download URL | extraer_datos_ine-1.0.1-py3-none-any.whl |
|---|---|
| Size | 9.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b0e7da29998fd1b5f90f16d8c7361e4778d4a1519c139e0c278ce6c0c2caaf69
|
|
BLAKE2b-256 checksum How to use checksums |
956df1793225db0dc30d3ca51d2f467ed1b0203cd816779c2af9d4c343264e81
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 30, 2026.
Transparency logSecurity for extraer-datos-ine 1.0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for extraer_datos_ine-1.0.1.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 30, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.