Python implementation of Open Charge Point Interface (OCPI) protocol based on fastapi.
Project description
Extrawest OCPI
Python implementation of Open Charge Point Interface (OCPI) protocol based on fastapi.
Requirements
Python >= 3.10
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
- 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:
...
- Initialize fastapi application
main.py
from py_ocpi import get_application
from py_ocpi.core.enums import RoleEnum, ModuleID
from py_ocpi.modules.versions.enums import VersionNumber
from crud import Crud
app = get_application(
version_numbers=[VersionNumber.v_2_1_1, VersionNumber.v_2_2_1],
roles=[RoleEnum.cpo],
modules=[ModuleID.locations],
crud=Crud,
)
- 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 now possible to initialize a few versions of ocpi for one project;
- Minimal required python version is 3.10;
- Add cdrs module;
- Add tariffs module;
- Add sessions module;
- Add tokens module;
- What's done so far:
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for extrawest_ocpi-2023.10.9-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dd1b0d3665a5a0244b267800cbaaffe38bc1ab38bb1502380414979aa75981d9 |
|
MD5 | 31bd83e56a45bd432ea6842366d9da5b |
|
BLAKE2b-256 | c26619911f354ade0f178ceac795efe5414b2ff372ab31576d9cc663de74961d |