Skip to content

Latest commit

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

askacharge — Python SDK

Official Python SDK for the askacharge.com API.

askacharge.com is a multi-tenant, white-label EV charge point management system (CSMS) built on open standards — OCPP 1.6J and 2.0.1 for chargers, OCPI 2.2 (CPO + eMSP) for roaming — with flat pricing (€20/month, unlimited chargers), QR payments without an app, Spanish tax-compliant invoicing (Verifactu / TicketBAI) and its own roaming hub (ES*ACH).

This SDK covers the external REST API (chargers and charging sessions) and verification of signed webhooks. Zero dependencies — Python standard library only.

Installation

pip install askacharge

Requires Python 3.9+.

Authentication

Create an API key in the askacharge.com dashboard (Settings → API keys). Keys look like ask_live_... and carry scopes (chargers:read, sessions:read).

fromaskachargeimportAskaChargeclient=AskaCharge(api_key="ask_live_...")

White-label deployment on your own domain? Point the client at it:

client=AskaCharge(api_key="ask_live_...", base_url="https://charging.yourbrand.com/api")

Chargers

forchargerinclient.chargers.list():
print(charger["id"], charger["status"], charger["location"])

Each charger: {"id", "status", "location", "lat", "lng"}status is the live OCPP status (Available, Charging, Faulted, ...).

Charging sessions

sessions=client.sessions.list(limit=100) # newest first, API caps at 200forsinsessions:
print(s["start_time"], s["energy_kwh"], "kWh", s["revenue"], "EUR")

Each session: {"id", "id_tag", "status", "energy_kwh", "revenue", "start_time", "stop_time", "co2_saved_g"}.

Webhooks

askacharge.com signs every outgoing webhook with HMAC-SHA256. The signature arrives in the X-AskaCharge-Signature header (sha256=<hex>), the event name in X-AskaCharge-Event, and the payload is {"event", "timestamp", "data"}. Verify against the raw request body:

fromaskachargeimportwebhooks, SignatureVerificationError# FastAPI examplefromfastapiimportFastAPI, Request, HTTPExceptionapp=FastAPI()
@app.post("/my-webhook")asyncdefhandle(request: Request):
body=awaitrequest.body()
signature=request.headers.get("X-AskaCharge-Signature", "")
try:
event=webhooks.construct_event(body, signature, secret="whsec-from-dashboard")
exceptSignatureVerificationError:
raiseHTTPException(status_code=400, detail="Bad signature")
ifevent["event"] =="session.stopped":
print("Charged", event["data"])
return {"ok": True}

Or just the boolean check: webhooks.verify_signature(body, signature, secret).

Error handling

fromaskachargeimportAskaCharge, AuthenticationError, ScopeError, APIErrortry:
client.sessions.list()
exceptAuthenticationError: # invalid or expired API key (401)
...
exceptScopeError: # key lacks sessions:read (403)
...
exceptAPIErrorase: # anything elseprint(e.status_code, e.body)

Links


En español

SDK oficial de Python para la API de askacharge.com, la plataforma de gestión de cargadores de vehículos eléctricos: CSMS multi-marca con OCPP 1.6J/2.0.1, roaming OCPI 2.2, pago por QR sin app y facturación fiscal española (Verifactu/TicketBAI) de serie, por €20/mes con cargadores ilimitados.

fromaskachargeimportAskaChargeclient=AskaCharge(api_key="ask_live_...")
print(client.chargers.list()) # tus cargadores con estado OCPP en vivoprint(client.sessions.list()) # últimas sesiones de carga

La API key se crea en el panel de askacharge.com (Configuración → API keys). Documentación completa en askacharge.com/askacharge/docs.html.

License

MIT

About

Official Python SDK for the askacharge.com EV charging platform API — OCPP/OCPI charge point management, sessions and signed webhooks

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages