OCPIPyBridge
is a Python library tailored for implementing the Open Charge Point Interface (OCPI) protocol. It offers structured models and validation for various OCPI entities, ideal for developers creating applications for EV charging infrastructure and services.
- Models for key OCPI entities:
Location
,EVSE
,Connector
,CDR
,Command
,Transaction
,Feedback
,Meter
,Reservation
,Tariff
,User
,Credentials
,ChargingProfile
,Token
, and more. - Validations align with OCPI standards using Pydantic.
- Supports diverse OCPI operations and functionalities.
Install OCPIPyBridge
using pip:
pip install OCPIPyBridge
Import the required models from OCPIPyBridge
:
from OCPIPyBridge.models import (
Location, EVSE, Connector, CDR, Command, Transaction, Feedback, Meter,
Reservation, Tariff, User, Credentials, ChargingProfile, Token, CommandResult,
CommandResponse, DisplayText, EnergyContract, LocationReferences, AuthorizationInfo
)
from OCPIPyBridge.models import Location
location_data = {
"id": "loc1",
"type": "ON_STREET",
"name": "Main Street Charging Station",
# ... other location details ...
}
location = Location(**location_data)
print(location.json())
from OCPIPyBridge.models import EVSE
evse_data = {
"uid": "evse12345",
# ... other EVSE details ...
}
evse = EVSE(**evse_data)
print(evse.json())
from OCPIPyBridge.models import ChargingProfile
profile_data = {
# ... charging profile details ...
}
charging_profile = ChargingProfile(**profile_data)
print(charging_profile.json())
... (Similar examples for other models)
from flask import Flask, request, jsonify
from OCPIPyBridge.models import CDR
app = Flask(__name__)
@app.route('/api/cdr', methods=['POST'])
def handle_cdr():
cdr_data = request.json
cdr = CDR(**cdr_data)
# Process and save CDR data
return jsonify({"message": "CDR data processed successfully."}), 200
if __name__ == '__main__':
app.run(debug=True)
from fastapi import FastAPI, HTTPException
from pydantic import ValidationError
from OCPIPyBridge.models import CDR
app = FastAPI()
@app.post('/api/cdr')
async def handle_cdr(cdr_data: CDR):
cdr_data.validate()
# Process and save CDR data
return {"message": "CDR data processed successfully."}
To contribute to OCPIPyBridge
:
- Fork the repository.
- Create a new feature branch.
- Develop your feature or fix.
- Update tests and documentation as needed.
- Commit and push changes.
- Open a pull request.
- Medium: dikibhuyan
- LinkedIn: Chinmoy Bhuyan
OCPIPyBridge
is under the MIT License. See the LICENSE file for details.
Keywords: #OCPI, EV Charging, Python Library, Electric Vehicle, Charging Network, Interoperability, Smart Charging, Open Standards, EVSE Management, Python Integration, Energy Services, Sustainable Transport, OCPI.