Python
Package avepay-mcf (PyPI)
Client sync (AvePay) et async (AsyncAvePay), même API. Python 3.9+, basé sur
httpx. Payload friendly (snake_case) avec échappatoire brute (clés camelCase).
pip install avepay-mcfCertifier une facture
from avepay.mcf import AvePay, AvePayError
avepay = AvePay(api_key="ak_live_…", isf="1")
mcf = avepay.mcf("EL02000015-1")
receipt = mcf.certify(
number="FV-2026-0001",
type="FV", # FV | FT | EV | ET (défaut FV)
operator={"id": 1, "name": "Awa"},
customer={"type": "PP", "name": "Client Comptant"},
items=[{"name": "Riz 25kg", "tax_group": "B", "unit_price": 15000, "quantity": 1}],
payments=[{"method": "cash", "amount": 15000}],
)
print(receipt.sig) # signature SECEF (codeSecef)
print(receipt.qr) # contenu QR
print(receipt.total_ttc) # 15000
print(receipt.counters) # Counters(tc=…, fvc=…, frc=…)tax_group déduit le tax_rate (A = 0 %, B = 18 %) ; method accepte cash/transfer/card/mobile/cheque/other. certify()/credit_note() acceptent un dict positionnel ou des kwargs.
Avoir (credit note)
avoir = mcf.credit_note(
number="FA-2026-0001",
from_=receipt, # dérive credit_note_ref = f"{nim}-{fvc}"
# ou: credit_note_ref="EL02000015-1-291",
credit_note_nature="COR", # COR | RAN | RAM | RRR (défaut COR)
operator={"id": 1, "name": "Awa"},
customer={"type": "PP"},
items=[{"name": "Riz 25kg", "tax_group": "B", "unit_price": 15000}],
payments=[{"method": "cash", "amount": 15000}],
)Info · cancel-pending · me
info = mcf.info() # mode, compteurs, marchand
mcf.cancel_pending() # annule une transaction 38h pendante
me = avepay.me() # org + NIM scopés + état des bridgesGestion d'erreurs
try:
mcf.certify(...)
except AvePayError as e:
print(e.code, e.http_status, e.message, e.request_id)
if e.is_bridge_offline:
... # MCF hors ligne — réessayer plus tardRetry réseau/5xx automatique (backoff + Idempotency-Key réutilisée entre tentatives).
Async
import asyncio
from avepay.mcf import AsyncAvePay
async def main():
avepay = AsyncAvePay(api_key="ak_live_…", isf="1")
receipt = await avepay.mcf("EL02000015-1").certify(
number="FV-2026-0001",
items=[{"name": "Riz 25kg", "tax_group": "B", "unit_price": 15000}],
payments=[{"method": "cash", "amount": 15000}],
)
print(receipt.sig)
asyncio.run(main())Webhooks
event = avepay.webhooks.verify(raw_body, signature_header)
# event["type"] : "cert.issued" | "mcf.connected" | "mcf.disconnected"