OCPI Python
A modern, production-ready Python implementation of the Open Charge Point Interface (OCPI) protocol built on FastAPI.
Supported OCPI versions: 2.3.0, 2.2.1, 2.1.1
OCPI Documentation: 2.3.0, 2.2.1, 2.1.1
Features
- Full OCPI 2.3.0 support - Including the new Payments module
- OCPI 2.2.1 and 2.1.1 compatibility - Backward compatible with previous versions
- Modern stack - Built with FastAPI 0.115+ and Pydantic v2
- Complete role support - CPO, EMSP, and PTP (Payment Terminal Provider)
- Comprehensive modules - Locations, Sessions, CDRs, Tokens, Tariffs, Commands, Charging Profiles, Hub Client Info, Credentials, and Payments
- Production-ready - Extensive test coverage (83%+), async/await support, and robust error handling
- Type-safe - Full Pydantic v2 validation with modern Python 3.11+ features
Installation
From PyPI (when published)
uv pip install ocpi-python
From GitHub
uv pip install git+https://github.com/elumobility/ocpi-python.git
In pyproject.toml
[project]
dependencies = [
"ocpi-python @ git+https://github.com/elumobility/ocpi-python.git",
]
Then install with:
uv pip install -e .
Quick Start
from ocpi import get_application
from ocpi.core.enums import RoleEnum, ModuleID
from ocpi.modules.versions.enums import VersionNumber
# Create OCPI application
app = get_application(
version_numbers=[VersionNumber.v_2_3_0],
roles=[RoleEnum.cpo],
modules=[ModuleID.locations],
)
# Run with: uvicorn main:app --reload
Supported Modules
| Module |
2.3.0 |
2.2.1 |
2.1.1 |
| Credentials |
✅ |
✅ |
✅ |
| Locations |
✅ |
✅ |
✅ |
| Sessions |
✅ |
✅ |
✅ |
| CDRs |
✅ |
✅ |
✅ |
| Tokens |
✅ |
✅ |
✅ |
| Tariffs |
✅ |
✅ |
✅ |
| Commands |
✅ |
✅ |
✅ |
| Charging Profiles |
✅ |
✅ |
❌ |
| Hub Client Info |
✅ |
✅ |
❌ |
| Payments |
✅ |
❌ |
❌ |
Requirements
| Package |
Version |
| Python |
>=3.11 |
| Pydantic |
>=2.0.0, <3.0.0 |
| pydantic-settings |
>=2.0.0 |
| FastAPI |
>=0.115.0, <1.0.0 |
| httpx |
>=0.27.0 |
Documentation
📚 Full Documentation - Complete API reference, tutorials, and examples
🤖 Using AI Coding Assistants?
If you’re using ChatGPT, Claude, GitHub Copilot, or Cursor, check out our LLM Assistance Guide for tips on getting the best results. The repository also includes a .cursorrules file for Cursor IDE users.
Contributing
Contributions are welcome! Please read our Contributing Guide and Code of Conduct before submitting a Pull Request.
We welcome:
- 🐛 Bug reports
- 💡 Feature requests
- 📝 Documentation improvements
- 🧪 Test coverage improvements
- 🔧 Code refactoring
See our Issue Templates for guidelines on reporting bugs or requesting features.
License
This project is dual-licensed under:
You may use this software under either license at your choice. See LICENSE for full details.
Credits
This library is based on the excellent work from extrawest/extrawest_ocpi, with significant enhancements including OCPI 2.3.0 support, Pydantic v2 migration, and comprehensive test coverage.
Maintainer: ELU Mobility
评论