OCPP - Open Charge Point Protocol
raw JSON → 2.1.0 verified Mon Apr 27 auth: no python
Python package implementing the JSON version of the Open Charge Point Protocol (OCPP). Supports OCPP 1.6, 2.0.1, and 2.1 via schema generation. Current version 2.1.0, requires Python >=3.11, release cadence is irregular with major version bumps.
pip install ocpp Common errors
error ImportError: cannot import name 'ChargePoint' from 'ocpp' ↓
cause Trying to import ChargePoint from wrong module. In v2, ChargePoint is in ocpp namespace, not ocpp.v16.
fix
Use: from ocpp import ChargePoint
error ModuleNotFoundError: No module named 'ocpp.v16' ↓
cause Installed ocpp version 2.0.0+ which may have restructured modules. Actually v16 still exists but make sure correct imports.
fix
Check pip list; if version >=2.0.0, use from ocpp.v16 import call
error AttributeError: 'ChargePoint' object has no attribute 'call' ↓
cause Not passing a WebSocket connection to ChargePoint constructor or not awaiting call.
fix
Ensure you pass a websocket connection: cp = ChargePoint(id, websocket) and use await cp.call(...)
Warnings
breaking In v2.0.0, the library dropped support for Python <3.11 and renamed several internal classes. ↓
fix Upgrade to Python >=3.11 and adjust imports: Payload classes are now in ocpp.v16.call and ocpp.v16.call_result instead of ocpp.v16.datatypes.
gotcha WebSocket connection is not part of the library; you must provide your own transport (e.g., websockets). ↓
fix Use websockets library to connect and pass the socket to ChargePoint constructor.
deprecated The 'Payload' suffix on call/call_result classes is deprecated in favor of un-suffixed names. ↓
fix Use BootNotification instead of BootNotificationPayload (still works but will be removed).
Imports
- ChargePoint wrong
from ocpp.v16 import ChargePointcorrectfrom ocpp import ChargePoint - ChargePointV16
from ocpp.v16 import ChargePoint as ChargePointV16 - call wrong
from ocpp import callcorrectfrom ocpp.v16 import call - call_result wrong
from ocpp import call_resultcorrectfrom ocpp.v16 import call_result
Quickstart
import asyncio
import logging
from ocpp import ChargePoint
from ocpp.v16 import call
logging.basicConfig(level=logging.INFO)
class ChargePointClient(ChargePoint):
async def send_boot_notification(self):
request = call.BootNotificationPayload(
charge_point_vendor='vendor',
charge_point_model='model'
)
response = await self.call(request)
logging.info(f"Boot response: {response}")
async def main():
cp = ChargePointClient('id', None)
await cp.send_boot_notification()
asyncio.run(main())