Skip to main content

Python library for Open Charge Point Interface (OCPI) protocol

Project description

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, and Credentials.
  • 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))

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.

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

OCPIPyBridge-0.1.2.tar.gz (2.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

OCPIPyBridge-0.1.2-py3-none-any.whl (2.8 kB view details)

Uploaded Python 3

File details

Details for the file OCPIPyBridge-0.1.2.tar.gz.

File metadata

  • Download URL: OCPIPyBridge-0.1.2.tar.gz
  • Upload date:
  • Size: 2.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.8

File hashes

Hashes for OCPIPyBridge-0.1.2.tar.gz
Algorithm Hash digest
SHA256 6e6f6c46af256df60afb56bf726392fc138ad35de1a801dd950de535e7765571
MD5 c04a054d1725d2ffca8d86d3fc6fdf45
BLAKE2b-256 0b1fac36ebb759f32e44c876176733b0dcd94f6c6bd08d09fa5487ac544a6d99

See more details on using hashes here.

File details

Details for the file OCPIPyBridge-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: OCPIPyBridge-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 2.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.8

File hashes

Hashes for OCPIPyBridge-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 396c8784fe6a4bf1f03e233e2d50231b3952207b09ff172c2b028fbefec4e0cb
MD5 c7558e868c5eb40627e1d0f079f9aeb1
BLAKE2b-256 cee2d9e19b07a37afebbea2136d35620dfe4731624d332efa4683e3fe72babec

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page