A curated list of open technology projects to sustain a stable climate, energy supply, biodiversity and natural resources.

ocpp

Python implementation of the Open Charge Point Protocol.
https://github.com/mobilityhouse/ocpp

Category: Consumption
Sub Category: Mobility and Transportation

Keywords

client electric-vehicles framework hacktoberfest ocpp server

Keywords from Contributors

archiving transforms measur optimize observation conversion compose generic animals projection

Last synced: about 17 hours ago
JSON representation

Repository metadata

Python implementation of the Open Charge Point Protocol (OCPP).

README.rst

          .. image:: https://github.com/mobilityhouse/ocpp/actions/workflows/pull-request.yml/badge.svg?style=svg
   :target: https://github.com/mobilityhouse/ocpp/actions/workflows/pull-request.yml

.. image:: https://img.shields.io/pypi/pyversions/ocpp.svg
   :target: https://pypi.org/project/ocpp/

.. image:: https://img.shields.io/readthedocs/ocpp.svg
   :target: https://ocpp.readthedocs.io/en/latest/

OCPP
----

Python package implementing the JSON version of the Open Charge Point Protocol
(OCPP). Currently OCPP 1.6 (errata v4), OCPP 2.0.1 (Edition 2 FINAL, 2022-12-15 and Edition 3 errata 2024-11)
are supported.

You can find the documentation on `rtd`_.

The purpose of this library is to provide the building blocks to construct a
charging station/charge point and/or charging station management system
(CSMS)/central system. The library does not provide a completed solution, as any
implementation is specific for its intended use. The documents in this library
should be inspected, as these documents provided guidance on how best to
build a complete solution.

Note: "OCPP 2.0.1 contains fixes for all the known issues, to date, not only
the fixes to the messages. This version replaces OCPP 2.0. OCA advises
implementers of OCPP to no longer implement OCPP 2.0 and only use version
2.0.1 going forward."

Installation
------------

You can either the project install from Pypi:

.. code-block:: bash

   $ pip install ocpp

Or clone the project and install it manually using:

.. code-block:: bash

   $ pip install .

Quick start
-----------

Below you can find examples on how to create a simple OCPP 1.6 or 2.0.1 Central
System/CSMS as well as the respective OCPP 1.6 or 2.0.1
Charging Station/Charge Point.

.. note::

   To run these examples the dependency websockets_ is required! Install it by running:

   .. code-block:: bash

      $ pip install websockets

Charging Station Management System (CSMS) / Central System
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The code snippet below creates a simple OCPP 2.0.1 CSMS which
is able to handle BootNotification calls. You can find a detailed explanation of the
code in the `Central System documentation`_.


.. code-block:: python

    import asyncio
    import logging
    import websockets
    from datetime import datetime

    from ocpp.routing import on
    from ocpp.v201 import ChargePoint as cp
    from ocpp.v201 import call_result
    from ocpp.v201.enums import RegistrationStatusType

    logging.basicConfig(level=logging.INFO)


    class ChargePoint(cp):
        @on('BootNotification')
        async def on_boot_notification(self, charging_station, reason, **kwargs):
            return call_result.BootNotificationPayload(
                current_time=datetime.utcnow().isoformat(),
                interval=10,
                status=RegistrationStatusType.accepted
            )


    async def on_connect(websocket, path):
        """ For every new charge point that connects, create a ChargePoint
        instance and start listening for messages.
        """
        try:
            requested_protocols = websocket.request_headers[
                'Sec-WebSocket-Protocol']
        except KeyError:
            logging.info("Client hasn't requested any Subprotocol. "
                     "Closing Connection")
            return await websocket.close()

        if websocket.subprotocol:
            logging.info("Protocols Matched: %s", websocket.subprotocol)
        else:
            # In the websockets lib if no subprotocols are supported by the
            # client and the server, it proceeds without a subprotocol,
            # so we have to manually close the connection.
            logging.warning('Protocols Mismatched | Expected Subprotocols: %s,'
                            ' but client supports  %s | Closing connection',
                            websocket.available_subprotocols,
                            requested_protocols)
            return await websocket.close()

        charge_point_id = path.strip('/')
        cp = ChargePoint(charge_point_id, websocket)

        await cp.start()


    async def main():
        server = await websockets.serve(
            on_connect,
            '0.0.0.0',
            9000,
            subprotocols=['ocpp2.0.1']
        )
        logging.info("WebSocket Server Started")
        await server.wait_closed()

    if __name__ == '__main__':
        asyncio.run(main())

Charging Station / Charge point
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. code-block:: python

    import asyncio

    from ocpp.v201.enums import RegistrationStatusType
    import logging
    import websockets

    from ocpp.v201 import call
    from ocpp.v201 import ChargePoint as cp

    logging.basicConfig(level=logging.INFO)


    class ChargePoint(cp):

        async def send_boot_notification(self):
            request = call.BootNotificationPayload(
                charging_station={
                    'model': 'Wallbox XYZ',
                    'vendor_name': 'anewone'
                },
                reason="PowerUp"
            )
            response = await self.call(request)

            if response.status == RegistrationStatusType.accepted:
                print("Connected to central system.")


    async def main():
        async with websockets.connect(
                'ws://localhost:9000/CP_1',
                subprotocols=['ocpp2.0.1']
        ) as ws:
            cp = ChargePoint('CP_1', ws)

            await asyncio.gather(cp.start(), cp.send_boot_notification())


    if __name__ == '__main__':
        asyncio.run(main())

Debugging
---------

Python's default log level is `logging.WARNING`. As result most of the logs
generated by this package are discarded. To see the log output of this package
lower the log level to `logging.DEBUG`.

.. code-block:: python

  import logging
  logging.basicConfig(level=logging.DEBUG)

However, this approach defines the log level for the complete logging system.
In other words: the log level of all dependencies is set to `logging.DEBUG`.

To lower the logs for this package only use the following code:

.. code-block:: python

  import logging
  logging.getLogger('ocpp').setLevel(level=logging.DEBUG)
  logging.getLogger('ocpp').addHandler(logging.StreamHandler())

Aknowledgements
---------------

Till the end of 2024, this project has been lead and maintained by `Auke Oosterhoff`_ and
`Jared Newell`_. We thank them for work their work! 

Since than, the project is lead by `Chad Meadowcroft`_, `Mohit Jain`_ and `Patrick Roelke`_.

License
-------

Except from the documents in `docs/v16` and `docs/v201` everything is licensed under MIT_.
© `The Mobility House`_

The documents in `docs/v16` and `docs/v201` are licensed under Creative Commons
Attribution-NoDerivatives 4.0 International Public License.

.. _Central System documentation: https://ocpp.readthedocs.io/en/latest/central_system.html
.. _MIT: https://github.com/mobilityhouse/ocpp/blob/master/LICENSE
.. _rtd: https://ocpp.readthedocs.io/en/latest/index.html
.. _The Mobility House: https://www.mobilityhouse.com/int_en/
.. _websockets: https://pypi.org/project/websockets/

.. _Auke Oosterhoff:  https://github.com/orangetux
.. _Jared Newell: https://github.com/Jared-Newell-Mobility
.. _Chad Meadowcroft: https://github.com/mdwcrft
.. _Mohit Jain: https://github.com/jainmohit2001
.. _Patrick Roelke: https://github.com/proelke

        

Owner metadata


GitHub Events

Total
Last Year

Committers metadata

Last synced: 6 days ago

Total Commits: 266
Total Committers: 44
Avg Commits per committer: 6.045
Development Distribution Score (DDS): 0.756

Commits in past year: 38
Committers in past year: 13
Avg Commits per committer in past year: 2.923
Development Distribution Score (DDS) in past year: 0.789

Name Email Commits
Auke Willem Oosterhoff 1****x 65
Jared-Newell-Mobility 1****y 59
Auke Willem Oosterhoff a****f@m****m 30
Patrick Roelke p****e 13
Laysa Uchoa 3****a 12
Chad 3****t 10
tropxy a****e@m****m 9
Mohit Jain 4****1 8
drc38 2****8 6
Adam Johnson me@a****u 4
André a****x@g****m 4
dependabot[bot] 4****] 3
Wafa Yahyaoui 1****h 3
Jérôme Benoit j****t@p****g 3
Andrew Mirsky a****w@m****t 3
Alex McLarty a****y@g****m 2
Ali Al-Alak 7****k 2
HugoJP1 8****1 2
Vince Chan 1****e 2
santiagosalamandri s****o@s****m 2
Hasan Hüseyin Pay h****y@g****m 1
Florian Maurer f****r@d****g 1
tomaz 5****l 1
scorpioprise 5****e 1
me-sosa 3****a 1
isabelle-tmh 1****h 1
esiebert 5****t 1
darander a****r@g****m 1
bengarrett1971 5****1 1
astrand a****d@l****e 1
and 14 more...

Committer domains:


Issue and Pull Request metadata

Last synced: 1 day ago

Total issues: 421
Total pull requests: 316
Average time to close issues: 7 months
Average time to close pull requests: about 2 months
Total issue authors: 205
Total pull request authors: 64
Average comments per issue: 3.0
Average comments per pull request: 1.7
Merged pull request: 230
Bot issues: 0
Bot pull requests: 16

Past year issues: 40
Past year pull requests: 65
Past year average time to close issues: about 1 month
Past year average time to close pull requests: 23 days
Past year issue authors: 29
Past year pull request authors: 16
Past year average comments per issue: 4.5
Past year average comments per pull request: 2.12
Past year merged pull request: 40
Past year bot issues: 0
Past year bot pull requests: 6

More stats: https://issues.ecosyste.ms/repositories/lookup?url=https://github.com/mobilityhouse/ocpp

Top Issue Authors

  • OrangeTux (67)
  • Jared-Newell-Mobility (31)
  • betovaca (7)
  • madhavsund (7)
  • deepakEnercent (7)
  • stig888881 (7)
  • carlbenjaminlyon (7)
  • josesilva1995 (6)
  • laysauchoa (6)
  • AlfredoNaef (6)
  • jainmohit2001 (5)
  • Ruban-A (5)
  • Aashutosh3804 (5)
  • vagio (5)
  • pamukcu09 (4)

Top Pull Request Authors

  • OrangeTux (66)
  • Jared-Newell-Mobility (59)
  • proelke (20)
  • tropxy (18)
  • dependabot[bot] (16)
  • laysauchoa (15)
  • jainmohit2001 (12)
  • mdwcrft (11)
  • drc38 (8)
  • ajmirsky (7)
  • wafa-yah (5)
  • adamchainz (4)
  • jerome-benoit (4)
  • a-alak (4)
  • alexmclarty (3)

Top Issue Labels

  • question (169)
  • bug (111)
  • enhancement (56)
  • stale (25)
  • For inclusion in release 1.0.0 (18)
  • good first issue (14)
  • ocpp2.1 (5)
  • duplicate (2)
  • help wanted (2)
  • documentation (2)
  • wontfix (1)
  • Repo Planning / Communication (1)
  • hypothesis (1)
  • need information (1)

Top Pull Request Labels

  • For inclusion in release 1.0.0 (31)
  • dependencies (16)
  • enhancement (11)
  • bug (10)
  • hacktoberfest-accepted (6)
  • ocpp2.1 (1)

Package metadata

pypi.org: ocpp

Python package implementing the JSON version of the Open Charge Point Protocol (OCPP).

  • Homepage: https://github.com/mobilityhouse/ocpp
  • Documentation: https://ocpp.readthedocs.io/en/latest/
  • Licenses: MIT
  • Latest release: 2.0.0 (published 4 months ago)
  • Last Synced: 2025-04-25T13:34:56.495Z (1 day ago)
  • Versions: 54
  • Dependent Packages: 4
  • Dependent Repositories: 18
  • Downloads: 65,290 Last month
  • Docker Downloads: 18
  • Rankings:
    • Downloads: 1.545%
    • Dependent packages count: 2.138%
    • Stargazers count: 2.664%
    • Average: 2.738%
    • Docker downloads count: 3.296%
    • Forks count: 3.335%
    • Dependent repos count: 3.45%
  • Maintainers (3)

Dependencies

poetry.lock pypi
  • alabaster 0.7.12 develop
  • asynctest 0.13.0 develop
  • atomicwrites 1.4.0 develop
  • babel 2.9.1 develop
  • certifi 2021.10.8 develop
  • charset-normalizer 2.0.7 develop
  • colorama 0.4.4 develop
  • coverage 6.3.2 develop
  • docutils 0.17.1 develop
  • flake8 4.0.1 develop
  • freezegun 1.1.0 develop
  • idna 3.3 develop
  • imagesize 1.3.0 develop
  • iniconfig 1.1.1 develop
  • jinja2 3.0.3 develop
  • markupsafe 2.0.1 develop
  • mccabe 0.6.1 develop
  • packaging 21.3 develop
  • pluggy 1.0.0 develop
  • py 1.11.0 develop
  • pycodestyle 2.8.0 develop
  • pyflakes 2.4.0 develop
  • pygments 2.10.0 develop
  • pyparsing 3.0.6 develop
  • pytest 6.2.5 develop
  • pytest-asyncio 0.16.0 develop
  • pytest-cov 3.0.0 develop
  • python-dateutil 2.8.2 develop
  • pytz 2021.3 develop
  • requests 2.26.0 develop
  • six 1.16.0 develop
  • snowballstemmer 2.2.0 develop
  • sphinx 2.4.5 develop
  • sphinxcontrib-applehelp 1.0.2 develop
  • sphinxcontrib-devhelp 1.0.2 develop
  • sphinxcontrib-htmlhelp 2.0.0 develop
  • sphinxcontrib-jsmath 1.0.1 develop
  • sphinxcontrib-qthelp 1.0.3 develop
  • sphinxcontrib-serializinghtml 1.1.5 develop
  • toml 0.10.2 develop
  • tomli 1.2.2 develop
  • urllib3 1.26.7 develop
  • attrs 21.2.0
  • importlib-metadata 4.2.0
  • importlib-resources 5.7.1
  • jsonschema 4.4.0
  • pyrsistent 0.18.0
  • typing-extensions 4.0.0
  • zipp 3.6.0
pyproject.toml pypi
  • asynctest ^0.13.0 develop
  • flake8 ^4.0.1 develop
  • freezegun ^1.1.0 develop
  • pytest ^6.2.5 develop
  • pytest-asyncio ^0.16.0 develop
  • pytest-cov ^3.0.0 develop
  • sphinx ^2.4.5 develop
  • jsonschema ^4.4.0
  • python ^3.7
.github/workflows/publish-to-pypi.yml actions
  • ./.github/actions/setup-python-build-env * composite
  • actions/checkout master composite
  • actions/setup-python v2 composite
.github/workflows/pull-request.yml actions
  • ./.github/actions/setup-python-build-env * composite
  • actions/checkout master composite
  • actions/setup-python v2 composite
.github/actions/setup-python-build-env/action.yml actions

Score: 21.669413206316438