Localhost API agent for Belgian eID cards using pythonbeid.
Project description
eID Agent (localhost API)
Agent local Python pour lire une carte eID belge via pythonbeid et exposer une API HTTP sur 127.0.0.1 pour un front web distant (HTTPS).
Fonctionnalités
- Bind local strict:
127.0.0.1uniquement - API FastAPI JSON UTF-8
- Session token en mémoire (TTL, Bearer token)
- CORS strict configurable par liste d’origines
- Rate limit simple sur
/v1/read - Mapping des données eID vers un contrat stable pour préremplissage formulaire
Installation
Package PyPI: pythonbeid-server
Module Python importable: eid_agent
Commande CLI installée: eid-agent
pip install -e .
Avec dépendances de test:
pip install -e ".[dev]"
Exécution
Mode recommandé:
eid-agent
Alternative:
python -m eid_agent
Configuration (variables d’environnement)
EID_AGENT_PORT(défaut:8765)EID_AGENT_ALLOWED_ORIGINS(ex:https://school.example,https://dev.school.example)EID_AGENT_SESSION_TTL_SECONDS(défaut:120)EID_AGENT_RATE_LIMIT_PER_MINUTE(défaut:10)EID_AGENT_LOG_LEVEL(défaut:INFO)
HTTPS local optionnel:
EID_AGENT_HTTPS=1EID_AGENT_TLS_CERT_PATHEID_AGENT_TLS_KEY_PATH
Si HTTPS est activé sans cert/key valides, l’agent échoue au démarrage.
API v1
Toutes les réponses JSON incluent:
ok(bool)timestamp(ISO8601 UTC)erroren cas d’échec
Health
GET /v1/health
Session
POST /v1/session
Retourne:
{
"ok": true,
"timestamp": "2026-03-03T09:00:00Z",
"token": "<opaque_token>",
"expires_in": 120
}
Status (auth requise)
GET /v1/status
Header:
Authorization: Bearer <token>
Read eID (auth requise)
POST /v1/read
Body:
{
"include_photo": true,
"fields": [
"first_names",
"first_name",
"last_name",
"national_number",
"birth_date",
"birth_place",
"nationality",
"sex",
"card_number",
"issuing_municipality",
"validity_start",
"validity_end",
"address_street",
"address_zip",
"address_city"
]
}
Si fields est omis, l’agent renvoie l’ensemble par défaut (incluant les champs eID usuels + adresse).
Logout (auth requise)
POST /v1/logout
Exemple côté front web
const sessionResp = await fetch("http://127.0.0.1:8765/v1/session", {
method: "POST"
});
const sessionJson = await sessionResp.json();
const token = sessionJson.token;
const readResp = await fetch("http://127.0.0.1:8765/v1/read", {
method: "POST",
headers: {
"Content-Type": "application/json",
"Authorization": `Bearer ${token}`
},
body: JSON.stringify({
include_photo: true
})
});
const readJson = await readResp.json();
console.log(readJson.data);
Important:
- Le domaine front doit être explicitement autorisé via
EID_AGENT_ALLOWED_ORIGINS. - Sans origine autorisée, aucun header
Access-Control-Allow-Originn’est envoyé.
Exemple curl
Créer une session:
curl -X POST http://127.0.0.1:8765/v1/session
Lire la carte:
curl -X POST http://127.0.0.1:8765/v1/read ^
-H "Authorization: Bearer <token>" ^
-H "Content-Type: application/json" ^
-d "{\"include_photo\":true}"
Confidentialité et logs
- Aucun token n’est loggé.
- Aucune donnée personnelle eID (nom, adresse, NISS, photo) n’est loggée.
- Logs techniques: démarrage/arrêt, config réseau, erreurs techniques.
Tests
pytest -q
Les tests API n’utilisent pas de matériel eID et injectent un backend simulé.
Publication PyPI (GitHub Actions)
Le workflow CI/CD est fourni ici:
.github/workflows/publish-pypi.yml
Il publie automatiquement sur PyPI avec Trusted Publishing (OIDC) quand un tag v* est poussé.
Configuration initiale (une seule fois)
- Sur PyPI, créer un Trusted Publisher pour ce projet avec:
- Owner GitHub
- Repo GitHub
- Workflow:
publish-pypi.yml - Environment:
pypi
- Sur GitHub, créer l'environnement
pypi(Settings > Environments).
Release
- Mettre à jour la version dans
pyproject.toml(ex:1.0.1). - Commit/push.
- Créer et pousser le tag correspondant:
git tag v1.0.1
git push origin v1.0.1
Le workflow vérifie que le tag correspond à la version (v<version>), build le package, puis publie sur PyPI.
Page web d'exemple
Un exemple de formulaire auto-rempli est disponible ici:
examples/web/index.html
Servir la page (PowerShell)
- Démarrer l'agent avec une origine CORS qui correspond au serveur statique:
$env:EID_AGENT_ALLOWED_ORIGINS="http://127.0.0.1:8080"
python -m eid_agent
- Dans un second terminal, servir la page:
python -m http.server 8080 --bind 127.0.0.1 --directory examples/web
- Ouvrir:
http://127.0.0.1:8080
Puis cliquer sur le bouton Lire eID et remplir.
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 pythonbeid_server-1.0.0.tar.gz.
File metadata
- Download URL: pythonbeid_server-1.0.0.tar.gz
- Upload date:
- Size: 14.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f695417d040ead666bd7df6180c12490ff9fc3c1ced577a4ff2b65121ffa58b1
|
|
| MD5 |
b44492904a8b1794394fea9810d0a11e
|
|
| BLAKE2b-256 |
c9db780557ceee8385121aada20639dd7a3525b97048d08b5b95ebaac1303073
|
Provenance
The following attestation bundles were made for pythonbeid_server-1.0.0.tar.gz:
Publisher:
publish-pypi.yml on Lapin-Blanc/pythonbeid-server
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pythonbeid_server-1.0.0.tar.gz -
Subject digest:
f695417d040ead666bd7df6180c12490ff9fc3c1ced577a4ff2b65121ffa58b1 - Sigstore transparency entry: 1017440787
- Sigstore integration time:
-
Permalink:
Lapin-Blanc/pythonbeid-server@07bbeb190e403c358e1de3bb90e3d62055947588 -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/Lapin-Blanc
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@07bbeb190e403c358e1de3bb90e3d62055947588 -
Trigger Event:
push
-
Statement type:
File details
Details for the file pythonbeid_server-1.0.0-py3-none-any.whl.
File metadata
- Download URL: pythonbeid_server-1.0.0-py3-none-any.whl
- Upload date:
- Size: 13.2 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 |
9114f6d30cf71137a4aead1d5a89f4e042a664b29164f398802b736e5e4074d4
|
|
| MD5 |
ec344b0a97c4e487870adbff8cae9513
|
|
| BLAKE2b-256 |
278df70db6fa6fb07f546a4c6dc99fcee3316f50b898db2746a8330e80d23416
|
Provenance
The following attestation bundles were made for pythonbeid_server-1.0.0-py3-none-any.whl:
Publisher:
publish-pypi.yml on Lapin-Blanc/pythonbeid-server
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pythonbeid_server-1.0.0-py3-none-any.whl -
Subject digest:
9114f6d30cf71137a4aead1d5a89f4e042a664b29164f398802b736e5e4074d4 - Sigstore transparency entry: 1017440864
- Sigstore integration time:
-
Permalink:
Lapin-Blanc/pythonbeid-server@07bbeb190e403c358e1de3bb90e3d62055947588 -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/Lapin-Blanc
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@07bbeb190e403c358e1de3bb90e3d62055947588 -
Trigger Event:
push
-
Statement type: