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 ocpi_py_bridge.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 ocpi_py_bridge.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 ocpi_py_bridge.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 ocpi_py_bridge.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.1.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.1-py3-none-any.whl (2.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: OCPIPyBridge-0.1.1.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.1.tar.gz
Algorithm Hash digest
SHA256 6f7d828a77bb731c73972a6da6a6d6157830380bc2b4b0df213d247489372804
MD5 339e5cf49e3c7cf9597970ee4edc19bb
BLAKE2b-256 a46eb54b5430fead6c0e72b1f3cd2c8fa1a983af0b592c211128260cdeb7c476

See more details on using hashes here.

File details

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

File metadata

  • Download URL: OCPIPyBridge-0.1.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 11b72707e161bde9f3323abcf1d5584d5366d8fdaddccbed54aba44cbab7f92b
MD5 acae6b1fd0377c7790c62a81ccf2b2f5
BLAKE2b-256 ae203871c877c1f1055f1db66cc17f5785efae5d4b64543dc5d4beef7765306d

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