Cliente Python para el portal de CFE (Comisión Federal de Electricidad) México
Project description
PyCfeMx
Cliente Python para el portal de CFE (Comisión Federal de Electricidad) México.
Permite consultar información de servicios de electricidad desde el portal "Mi Espacio" de CFE.
Instalación
pip install pycfemx
Uso
Async
import asyncio
from pycfemx import CFEClient
async def main():
async with CFEClient() as client:
await client.login("tu_usuario", "tu_password")
# Obtener información de un servicio específico
info = await client.get_info()
print(f"Monto: {info.amount_due}")
asyncio.run(main())
Sync
from pycfemx import CFESyncClient
with CFESyncClient() as client:
client.login("tu_usuario", "tu_password")
info = client.get_info()
print(f"Monto: {info.amount_due}")
Múltiples servicios
Un usuario de CFE puede tener varios servicios (domicilios) asociados a su cuenta:
import asyncio
from pycfemx import CFEClient
async def main():
async with CFEClient() as client:
await client.login("tu_usuario", "tu_password")
# Listar todos los servicios
services = await client.get_services()
# Obtener información de cada servicio
for service in services:
info = await client.get_info(service.service_number)
print(f"\n{service.alias}:")
print(f" Monto: {info.amount_due}")
print(f" Vence: {info.due_date}")
print(f" Estado: {info.payment_status}")
asyncio.run(main())
Historial de recibos
import asyncio
from pycfemx import CFEClient
async def main():
async with CFEClient() as client:
await client.login("tu_usuario", "tu_password")
info = await client.get_info()
print("Últimos recibos:")
for receipt in info.receipts:
pdf = "PDF" if receipt.pdf_available else ""
xml = "XML" if receipt.xml_available else ""
print(f" {receipt.period}: {pdf} {xml}")
asyncio.run(main())
API
CFEClient (async) / CFESyncClient (sync)
Ambos clientes exponen los mismos métodos. CFEClient es async, CFESyncClient es su equivalente síncrono.
| Método | Descripción |
|---|---|
login(username, password) |
Inicia sesión en el portal de CFE |
get_services() |
Devuelve la lista de servicios disponibles |
get_info(service_number=None) |
Devuelve información del servicio especificado (o el actual) |
close() |
Cierra la sesión |
Modelos
Service
| Atributo | Tipo | Descripción |
|---|---|---|
service_number |
str |
Número de servicio (12 dígitos) |
alias |
str |
Nombre corto del servicio |
display_name |
str |
Nombre completo (alias - número) |
ServiceInfo
| Atributo | Tipo | Descripción |
|---|---|---|
service_number |
str |
Número de servicio |
owner_name |
str |
Nombre del titular |
address |
str |
Dirección del servicio |
amount_due |
str |
Monto a pagar (ej: "$65") |
consumption_period_text |
str |
Período de consumo (ej: "10 DIC 25 al 09 FEB 26") |
due_date_text |
str |
Fecha límite de pago (ej: "26 FEB 26") |
payment_status |
str |
Estado: VIGENTE, PAGADO o VENCIDO |
receipts |
list[Receipt] |
Historial de recibos |
user_type |
str | None |
Tipo de usuario (ej: "CFECONTIGO") |
due_date |
date | None |
Fecha límite de pago parseada |
consumption_start |
date | None |
Inicio del período de consumo |
consumption_end |
date | None |
Fin del período de consumo |
Receipt
| Atributo | Tipo | Descripción |
|---|---|---|
period |
str |
Período del recibo (ej: "FEB 2026") |
pdf_available |
bool |
Si el PDF está disponible |
xml_available |
bool |
Si el XML (CFDI) está disponible |
Excepciones
| Excepción | Descripción |
|---|---|
CFEError |
Excepción base |
CFEAuthError |
Error de autenticación |
CFEConnectionError |
Error de conexión |
CFESessionExpiredError |
Sesión expirada |
CFEServiceNotFoundError |
Servicio no encontrado |
Requisitos
- Python 3.10+
- aiohttp
- beautifulsoup4
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 pycfemx-0.1.0.tar.gz.
File metadata
- Download URL: pycfemx-0.1.0.tar.gz
- Upload date:
- Size: 9.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
39a2a32a1e745ba61f5f92e076fef837f1504bf741fd517f0510b949d788ae5d
|
|
| MD5 |
cdac2a30a1f7698b4d71005614103c80
|
|
| BLAKE2b-256 |
3709bacafee6c62ea975386a890c58dbd20090d4f6589755bc0a6235fdaa0023
|
Provenance
The following attestation bundles were made for pycfemx-0.1.0.tar.gz:
Publisher:
python-publish.yml on oamilkar/PyCfeMx
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pycfemx-0.1.0.tar.gz -
Subject digest:
39a2a32a1e745ba61f5f92e076fef837f1504bf741fd517f0510b949d788ae5d - Sigstore transparency entry: 967740308
- Sigstore integration time:
-
Permalink:
oamilkar/PyCfeMx@f16893a3ce090ac2e18fad406c3a2ad70c2cbc52 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/oamilkar
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@f16893a3ce090ac2e18fad406c3a2ad70c2cbc52 -
Trigger Event:
release
-
Statement type:
File details
Details for the file pycfemx-0.1.0-py3-none-any.whl.
File metadata
- Download URL: pycfemx-0.1.0-py3-none-any.whl
- Upload date:
- Size: 12.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
79a3dd61543a0d6a98b1bbcecdc0241bda7ff264c3ff2737fd73d955035711e1
|
|
| MD5 |
d9792bf8b01601622ec5d4e32ed2da4a
|
|
| BLAKE2b-256 |
867980212fe431e8290b517d5dcd7141263160fccd9a51565e2f58d500b7d2d8
|
Provenance
The following attestation bundles were made for pycfemx-0.1.0-py3-none-any.whl:
Publisher:
python-publish.yml on oamilkar/PyCfeMx
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pycfemx-0.1.0-py3-none-any.whl -
Subject digest:
79a3dd61543a0d6a98b1bbcecdc0241bda7ff264c3ff2737fd73d955035711e1 - Sigstore transparency entry: 967740359
- Sigstore integration time:
-
Permalink:
oamilkar/PyCfeMx@f16893a3ce090ac2e18fad406c3a2ad70c2cbc52 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/oamilkar
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@f16893a3ce090ac2e18fad406c3a2ad70c2cbc52 -
Trigger Event:
release
-
Statement type: