{"id":21314488,"url":"https://github.com/polyconseil/ocpp-codec","last_synced_at":"2025-08-08T13:25:37.815Z","repository":{"id":89419139,"uuid":"228431859","full_name":"Polyconseil/ocpp-codec","owner":"Polyconseil","description":"A Python OCPP encoder","archived":false,"fork":false,"pushed_at":"2020-06-01T13:49:54.000Z","size":61,"stargazers_count":0,"open_issues_count":0,"forks_count":2,"subscribers_count":19,"default_branch":"master","last_synced_at":"2025-01-22T10:16:57.653Z","etag":null,"topics":["encoder","ocpp","python3","serialization"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Polyconseil.png","metadata":{"files":{"readme":"README.rst","changelog":"CHANGELOG.rst","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2019-12-16T16:46:45.000Z","updated_at":"2020-06-01T13:49:52.000Z","dependencies_parsed_at":"2023-03-11T07:30:50.641Z","dependency_job_id":null,"html_url":"https://github.com/Polyconseil/ocpp-codec","commit_stats":{"total_commits":46,"total_committers":3,"mean_commits":"15.333333333333334","dds":0.4782608695652174,"last_synced_commit":"71b79632eeb18d9b0865070b18cf81888656cfa1"},"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Polyconseil%2Focpp-codec","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Polyconseil%2Focpp-codec/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Polyconseil%2Focpp-codec/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Polyconseil%2Focpp-codec/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Polyconseil","download_url":"https://codeload.github.com/Polyconseil/ocpp-codec/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243790999,"owners_count":20348385,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["encoder","ocpp","python3","serialization"],"created_at":"2024-11-21T18:13:18.914Z","updated_at":"2025-03-15T21:15:43.892Z","avatar_url":"https://github.com/Polyconseil.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"ocpp-codec - OCPP messages encoder-decoder\n==========================================\n\n.. image:: https://secure.travis-ci.org/Polyconseil/ocpp-codec.png?branch=lburg/setting_up_travis\n    :target: http://travis-ci.org/Polyconseil/ocpp-codec/\n\n*ocpp-codec* provides dataclasses definitions of OCPP messages and types, in both version 1.6 and 2.0 of the protocol.\n\nIt also provides a JSON pre-serializer and post-deserializer to exchange messages (see below).\n\nIt **does not** provide an API to write an OCPP server or client.\n\nPre-serializer\n--------------\n\nTurn an OCPP message dataclass instance into a basic Python dict representing the JSON payload:\n\n.. code-block:: python\n\n    import datetime\n    import json\n\n    from ocpp_codec import serializer\n    from ocpp_codec import structure\n    from ocpp_codec.v20 import messages\n    from ocpp_codec.v20 import types\n\n    response_payload = messages.BootNotification.Response(\n        datetime.datetime(2013, 2, 1, 20, 53, 32, 486000, datetime.timezone.utc),\n        300,\n        types.RegistrationStatusEnum.Accepted,\n    )\n    call_result = structure.CallResult(\"19223201\", response_payload)\n    pre_serialized = serializer.serialize(call_result)\n\n    print(pre_serialized)\n    # [3, '19223201', {'currentTime': '2013-02-01T20:53:32.486000+00:00', 'interval': 300, 'status': 'Accepted'}]\n\n    print(json.dumps(pre_serialized))\n    # [3, \"19223201\", {\"currentTime\": \"2013-02-01T20:53:32.486000+00:00\", \"interval\": 300, \"status\": \"Accepted\"}]\n\nAs you can see in this example the pre-serialized data already converted ``datetime`` and ``enum.Enum`` fields to\nstrings. The result can then directly be given to ``json.dumps`` to get the JSON string to be sent as an RPC.\n\nPost-deserializer\n-----------------\n\nTurn a Python dict (extracted from a JSON string) to an OCPP message dataclass:\n\n.. code-block:: python\n\n    import json\n\n    from ocpp_codec import compat\n    from ocpp_codec import serializer\n    from ocpp_codec.v20 import messages\n\n    deserialized = json.loads(\"\"\"[3, \"19223201\", {\"currentTime\": \"2013-02-01T20:53:32.486000+00:00\", \"interval\": 300, \"status\": \"Accepted\"}]\"\"\")\n    call_result = serializer.parse(deserialized, 'BootNotification', protocol=compat.OcppJsonProtocol.v20)\n\n    print(call_result.uniqueId)\n    # 19223201\n\n    print(call_result.payload)\n    # BootNotification.Response(currentTime=datetime.datetime(2013, 2, 1, 20, 53, 32, 486000, tzinfo=tzutc()), interval=300, status=\u003cRegistrationStatusEnum.Accepted: 'Accepted'\u003e)\n\nAs you can see in this example, the post-deserialized payload is a dataclass holding python data types such as ``datetime`` and ``enum.Enum``.\n\n\nImplemented messages\n--------------------\n\nYou can find messages implemented for `OCPP version 1.6 here`_ and for `OCPP version 2.0 here`_.\n\n.. _`OCPP version 1.6 here`: https://github.com/Polyconseil/ocpp-codec/blob/master/ocpp_codec/v16/messages.py\n.. _`OCPP version 2.0 here`: https://github.com/Polyconseil/ocpp-codec/blob/master/ocpp_codec/v20/messages.py\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpolyconseil%2Focpp-codec","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpolyconseil%2Focpp-codec","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpolyconseil%2Focpp-codec/lists"}