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.3.tar.gz (2.9 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.3-py3-none-any.whl (2.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: OCPIPyBridge-0.1.3.tar.gz
  • Upload date:
  • Size: 2.9 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.3.tar.gz
Algorithm Hash digest
SHA256 a8a35db49fe34db7fcc364202869c856ffbbdfcda3f42c4de47d6da7d7def270
MD5 cbf4156c472287264c57bcd91bf9efe2
BLAKE2b-256 8c2ef786676fcd8849b062a26d8adbfc974c32a515052761acca8469ddcaf59e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: OCPIPyBridge-0.1.3-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.3-py3-none-any.whl
Algorithm Hash digest
SHA256 cdfcf84a272474a41a3947f55b01324b1fff22c82dcba12118aedf2cb6dab42d
MD5 63f83cb794cdc22cf93e42ae8b0aa457
BLAKE2b-256 536d1c602254f8e1ea549b22530f55745dce9b4508c008d8b9229440ad1b3c25

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