Skip to main content

Python implementation of Open Charge Point Interface (OCPI) protocol based on fastapi.

Project description

Extrawest OCPI

pre-commit Code style: black Checked with mypy commit-check


Python implementation of Open Charge Point Interface (OCPI) protocol based on fastapi.


Requirements


Python >= 3.11.1

Installation


  pip install extrawest-ocpi

Make sure to install any ASGI-server supported by fastapi:

  pip install uvicorn

Environment Variables


To use this project, you will need to add the following environment variables to your .env file

API_KEY ANOTHER_API_KEY PROJECT_NAME BACKEND_CORS_ORIGINS OCPI_HOST OCPI_PREFIX PUSH_PREFIX COUNTRY_CODE PARTY_ID

Usage/Examples


  1. Implement and connect your db methods inside this Crud class.

crud.py

from typing import Any, Tuple
from py_ocpi.core.enums import ModuleID, RoleEnum, Action


class Crud:

    @classmethod
    async def get(cls, module: ModuleID, role: RoleEnum, id, *args, **kwargs) -> Any:
        ...

    @classmethod
    async def list(cls, module: ModuleID, role: RoleEnum, filters: dict, *args, **kwargs) -> Tuple[list, int, bool]:
        ...

    @classmethod
    async def create(cls, module: ModuleID, role: RoleEnum, data: dict, *args, **kwargs) -> Any:
        ...

    @classmethod
    async def update(cls, module: ModuleID, role: RoleEnum, data: dict, id, *args, **kwargs) -> Any:
        ...

    @classmethod
    async def delete(cls, module: ModuleID, role: RoleEnum, id, *args, **kwargs):
        ...

    @classmethod
    async def do(cls, module: ModuleID, role: RoleEnum, action: Action, *args, data: dict = None, **kwargs) -> Any:
        ...
  1. Implement all needed module adapters inside Adapter class.

adapter.py

from py_ocpi.modules.versions.enums import VersionNumber
from py_ocpi.modules.locations.v_2_2_1.schemas import Location


class Adapter:

    @classmethod
    def location_adapter(cls, data: dict, version: VersionNumber) -> Location:
        """Return location."""
        return Location(**data)
  1. Initialize fastapi application

main.py

from py_ocpi import get_application
from py_ocpi.core.enums import RoleEnum
from py_ocpi.modules.versions.enums import VersionNumber

from adapter import Adapter
from crud import Crud


app = get_application(
    version_numbers=[VersionNumber.v_2_2_1],
    roles=[RoleEnum.cpo],
    crud=Crud,
    adapter=Adapter,
)
  1. Run
  uvicorn main:app --reload

API Reference


As this project is based on fastapi, use /docs or redoc/ to check the documentation after the project is running.

Example: http://127.0.0.1:8000/ocpi/docs/

Roadmap


  • [in progress] Add support for OCPI v2.1.1
    • What's done so far:
      • Add version, credentials and locations module;
      • Add support for initializing v2.1.1 (It's possible to initialize only one version for one project);

Related


The project was created through inspiration and adaptation of this project PY_OCPI.

License


This project is licensed under the terms of the MIT license.

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

extrawest_ocpi-2023.9.20.tar.gz (53.1 kB view details)

Uploaded Source

Built Distribution

extrawest_ocpi-2023.9.20-py3-none-any.whl (69.6 kB view details)

Uploaded Python 3

File details

Details for the file extrawest_ocpi-2023.9.20.tar.gz.

File metadata

  • Download URL: extrawest_ocpi-2023.9.20.tar.gz
  • Upload date:
  • Size: 53.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.18

File hashes

Hashes for extrawest_ocpi-2023.9.20.tar.gz
Algorithm Hash digest
SHA256 1209b853fb1bb2db66d377e6557cce4f17e807e7a1aff64b8882f8c07d0ef9a9
MD5 8cae1c5d3c414f5097ddb282662f04f5
BLAKE2b-256 add391c495fb14eb7ba080d362267ca3d40480b9e4171ff207cf62bafd3b380a

See more details on using hashes here.

File details

Details for the file extrawest_ocpi-2023.9.20-py3-none-any.whl.

File metadata

File hashes

Hashes for extrawest_ocpi-2023.9.20-py3-none-any.whl
Algorithm Hash digest
SHA256 edd35e39f06547d44990ce1360368e8dde91471fe3360d6a7b04518ac0d435e0
MD5 80c461cd90ae89a3e468970f4ff2a98a
BLAKE2b-256 c14a99251ceb797a4a5037f52148a92bbddf882b10fdc5571a729d1b818b9d00

See more details on using hashes here.

Supported by

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