Python library for Open Charge Point Interface (OCPI) protocol
Project description
OCPIPyBridge: A Python Library for OCPI Protocol
Overview
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.
Features
- Models for key OCPI entities:
Location,EVSE,Connector,CDR,Command,Transaction,Feedback,Meter,Reservation,Tariff,User, andCredentials. - Validations align with OCPI standards using Pydantic.
- Supports diverse OCPI operations and functionalities.
Installation
Install OCPIPyBridge using pip:
pip install OCPIPyBridge
Usage
Import the required models from OCPIPyBridge:
from OCPIPyBridge.models import Location, EVSE, Connector, CDR, Command, Transaction, Feedback, Meter, Reservation, Tariff, User, Credentials
Model Usage Examples
Example of how to instantiate and use each model:
Location
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())
... (Similar examples for other models)
Integration with Flask/FastAPI
Flask Example
from flask import Flask, request, jsonify
from OCPIPyBridge.models import CDR
app = Flask(__name__)
@app.route('/api/cdr', methods=['POST'])
def handle_cdr():
try:
cdr_data = request.json
cdr = CDR(**cdr_data)
# Process and save CDR data
return jsonify({"message": "CDR data processed successfully."}), 200
except ValueError as e:
return jsonify({"error": str(e)}), 400
if __name__ == '__main__':
app.run(debug=True)
FastAPI Example
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):
try:
cdr_data.validate()
# Process and save CDR data
return {"message": "CDR data processed successfully."}
except ValidationError as e:
raise HTTPException(status_code=400, detail=str(e))
Start Transaction Command
The StartTransaction command initiates a charging session for an electric vehicle. Below is an example of how to create and use this command:
from OCPIPyBridge.models import Command, StartSessionCommand
# Example data for starting a session
start_session_data = {
"evse_id": "evse12345",
"user_id": "user67890"
}
# Create a StartSessionCommand instance
start_session_command = StartSessionCommand(**start_session_data)
# Create the main Command instance with the StartSessionCommand
command_data = {
"id": "cmd123",
"type": "START_SESSION",
"data": start_session_command
}
command = Command(**command_data)
print(command.json())
In this example, StartSessionCommand is a submodel of Command tailored specifically for the START_SESSION command type. It includes necessary fields like evse_id and user_id. These details are crucial for identifying the EVSE (Electric Vehicle Supply Equipment) and the user initiating the transaction.
Contributing
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.
Author
- Medium: dikibhuyan
- LinkedIn: Chinmoy Bhuyan
License
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.
Project details
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 OCPIPyBridge-0.1.4.tar.gz.
File metadata
- Download URL: OCPIPyBridge-0.1.4.tar.gz
- Upload date:
- Size: 3.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
37e687e901096d5300ab1136817d0f60f3843d1616424c1d211bb6893178ca5d
|
|
| MD5 |
51070d95bc9c56c2cdb501be453abd35
|
|
| BLAKE2b-256 |
02976113615273dd3d7a91d2e553fd434fdbf2330f753662f8cc6ca7eed92da3
|
File details
Details for the file OCPIPyBridge-0.1.4-py3-none-any.whl.
File metadata
- Download URL: OCPIPyBridge-0.1.4-py3-none-any.whl
- Upload date:
- Size: 3.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
86db449017b65595545db68d4dbba44aac45cf133691dea9eb33218a1fd16774
|
|
| MD5 |
ffed8b0516da82f72d65ee728e8d9c80
|
|
| BLAKE2b-256 |
6ca4259b75759b29c9d01e2d09d35148cbbc8ecc7c307b63187b75b35702f413
|