Skip to content

hyndex/OCPIPyBridge

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

OCPIPyBridge: A Python Library for OCPI Protocol

Tests Made with Love Electric Vehicle Eco Friendly Tree

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, Credentials, ChargingProfile, Token, and more.
  • 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, ChargingProfile, Token, CommandResult,
    CommandResponse, DisplayText, EnergyContract, LocationReferences, AuthorizationInfo
)

Model Usage Examples

Location Example

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())

EVSE Example

from OCPIPyBridge.models import EVSE

evse_data = {
    "uid": "evse12345",
    # ... other EVSE details ...
}

evse = EVSE(**evse_data)
print(evse.json())

Charging Profile Example

from OCPIPyBridge.models import ChargingProfile

profile_data = {
    # ... charging profile details ...
}

charging_profile = ChargingProfile(**profile_data)
print(charging_profile.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():
    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)

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):
    cdr_data.validate()
    # Process and save CDR data
    return {"message": "CDR data processed successfully."}

Contributing

To contribute to OCPIPyBridge:

  1. Fork the repository.
  2. Create a new feature branch.
  3. Develop your feature or fix.
  4. Update tests and documentation as needed.
  5. Commit and push changes.
  6. Open a pull request.

Author

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.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages