{"id":28406737,"url":"https://github.com/eclipse-ditto/ditto-clients-python","last_synced_at":"2026-03-04T11:32:20.890Z","repository":{"id":44163869,"uuid":"372869125","full_name":"eclipse-ditto/ditto-clients-python","owner":"eclipse-ditto","description":"Eclipse Ditto™: Digital Twin framework - Client SDK for Python","archived":false,"fork":false,"pushed_at":"2023-05-04T17:54:24.000Z","size":75,"stargazers_count":14,"open_issues_count":1,"forks_count":4,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-06-29T09:38:55.980Z","etag":null,"topics":["client-sdk","eclipse-ditto","python","python-library"],"latest_commit_sha":null,"homepage":"https://eclipse.org/ditto/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"epl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/eclipse-ditto.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2021-06-01T15:00:28.000Z","updated_at":"2025-03-21T02:51:36.000Z","dependencies_parsed_at":"2025-06-29T09:31:33.955Z","dependency_job_id":"286e62e3-18d9-44af-9b09-c2d91deb00e6","html_url":"https://github.com/eclipse-ditto/ditto-clients-python","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/eclipse-ditto/ditto-clients-python","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eclipse-ditto%2Fditto-clients-python","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eclipse-ditto%2Fditto-clients-python/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eclipse-ditto%2Fditto-clients-python/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eclipse-ditto%2Fditto-clients-python/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/eclipse-ditto","download_url":"https://codeload.github.com/eclipse-ditto/ditto-clients-python/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eclipse-ditto%2Fditto-clients-python/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30078992,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-04T08:01:56.766Z","status":"ssl_error","status_checked_at":"2026-03-04T08:00:42.919Z","response_time":59,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["client-sdk","eclipse-ditto","python","python-library"],"created_at":"2025-06-01T22:36:44.604Z","updated_at":"2026-03-04T11:32:20.873Z","avatar_url":"https://github.com/eclipse-ditto.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Eclipse Ditto Client SDK for Python\n\n[![Join the chat at https://gitter.im/eclipse/ditto](https://badges.gitter.im/eclipse/ditto.svg)](https://gitter.im/eclipse/ditto?utm_source=badge\u0026utm_medium=badge\u0026utm_campaign=pr-badge\u0026utm_content=badge)\n[![License](https://img.shields.io/badge/License-EPL%202.0-green.svg)](https://opensource.org/licenses/EPL-2.0)\n\nThis repository contains the Python client SDK for [Eclipse Ditto](https://eclipse.org/ditto/).\n\n## Table of Contents\n* [Installation](#Installation)\n* [Creating and connecting a client](#Creating-and-connecting-a-client)\n* [Working with features](#Working-with-features)\n  * [Creating a new feature instance](#Creating-a-new-feature-instance)\n  * [Modifying a feature's property](#Modifying-a-feature's-property)\n  * [Deleting a feature's property](#Deleting-a-feature's-property)\n  * [Deleting a feature](#Deleting-a-feature)\n* [Subscribing and handling messages](#Subscribing-and-handling-messages)\n* [Logging](#Logging)\n\n## Installation\n\nDownload the sources and execute the following command:\n\n```commandline\nmake install\n```\n\n**_NOTE:_** Python \u003e=3.6 is required in order to use the library.\n\n## Creating and connecting a client\n\nIt is a good practice to have a defined behaviour after connecting or disconnecting the client.\n\n```python    \ndef on_connect(ditto_client: Client):\n    print(\"Ditto client connected\")\n\ndef on_disconnect(ditto_client: Client):\n    print(\"Ditto client disconnected\")\n```\n\nWith these configurations a client instance can be created.\n\n```python\nclient = Client(on_connect=on_connect, on_disconnect=on_disconnect)\n```\n\nAfter the client is created, it's ready to be connected.\n\n```python\nclient.connect(host=\"localhost\")\n```\n\nThe client can be also connected with custom connection configurations.\n\n```python\nclient.connect(host=\"localhost\", port=1883, keep_alive=60)\n```\n\nFull example of the basic client connection can be found [here](examples/client_connect.py).\n\n**_NOTE:_** It is possible to create a client instance by inheriting the Client class. The `on_connect` and `on_disconnect` callback methods should be overridden in order to be configured. A separate method can be created in order to connect the client. This allows the client to be connected with custom configurations. Full example of the client connection as a class can be found [here](examples/client_connect_as_class.py).\n\n**_NOTE:_** It is also possible to provide an external Paho instance for communication by using the `paho_client` property of the Client class. Full example of the client connection using an external Paho client can be found [here](examples/client_connect_as_class_external_paho.py).\n\n## Working with features\n\nBefore sending any commands regarding features, there must be a client connected.\n\n### Creating a new feature instance\n\nA feature instance can be created with definition ID, properties, and/or desired properties.\n\n```python\nmyFeature = Feature()\n    .with_definition_from(\"my.model.namespace:FeatureModel:1.0.0\")\n    .with_property(\"myProperty\", \"myValue\")\n```\n\nThen a Ditto command can be created. Modify acts as an upsert - it either creates a feature or updates it if it already exists.\nThe ID provided in `feature()` is used to recognize the feature which will be created/updated. \n\n```python\ncommand = Command(NamespacedID().from_string(\"test.ns:test-name\"))\n    .feature(\"МyFeatureID\")\n    .twin()\n    .modify(myFeature)\n```\n\nThe command can be now wrapped in an envelope and sent.\n\n```python\nenvelope = command.envelope(response_required=False)\nclient.send(envelope)\n```\n\n### Modifying a feature's property\n\nModify overrides the current feature's property.\n\n```python\ncommand = Command(NamespacedID().from_string(\"test.ns:test-name\"))\n    .feature_property(\"МyFeatureID\", \"myProperty\")\n    .twin()\n    .modify(\"myModifiedValue\")\n```\n\nThe command can be now wrapped in an envelope and sent.\n\n```python\nenvelope = command.envelope(response_required=False)\nclient.send(envelope) \n```\n\n### Deleting a feature's property\n\nDelete command is created using the feature's ID and the property's name.\n\n```python\ncommand = Command(NamespacedID().from_string(\"test.ns:test-name\"))\n    .feature_property(\"МyFeatureID\", \"myProperty\")\n    .twin()\n    .delete()\n```\n\nThe command can now be wrapped in an envelope and sent.\n```python\nenvelope = command.envelope(response_required=False)\nclient.send(envelope) \n```\n\n### Deleting a feature\n\nA feature can be deleted with a command with the appropriate feature's ID.\n\n```python\ncommand = Command(NamespacedID().from_string(\"test.ns:test-name\"))\n    .feature(\"МyFeatureID\")\n    .twin()\n    .delete()\n```\n\nThe command can now be wrapped in an envelope and sent.\n```python\nenvelope = command.envelope(response_required=False)\nclient.send(envelope) \n```\n\nFull example of working with features can be found [here](examples/working_with_features.py).\n\n## Subscribing and handling messages\n\nEvery client instance can subscribe for incoming Ditto messages. This usually happens right after the client is connected.\n\n```python\ndef on_connect(ditto_client: Client):\n    print(\"Ditto client connected\")\n\n    # Subscribe for incoming messages\n    ditto_client.subscribe(on_message)\n```\n\n**_NOTE:_** Multiple handlers can be added for Ditto messages processing.\n\nIt is a good practice to clear all subscriptions if the client gets disconnected.\n\n```python\ndef on_disconnect(ditto_client: Client):\n    ditto_client.unsubscribe(on_message)\n```\n\n**_NOTE:_** If no message handlers are provided to `unsubscribe()` then all will be removed.\n\nNow when a message is received it can be handled and replied to.\n\n```python\ndef on_message(request_id: str, message: Envelope):\n    # get the thing id from the topic of the incoming message\n    incoming_thing_id = NamespacedID(message.topic.namespace, message.topic.entity_id)\n\n    # create an example outbox message and reply\n    live_message = Message(incoming_thing_id).outbox(message_subject).with_payload(\n        dict(a=\"b\", x=2))\n    \n    # generate the respective Envelope\n    response_envelope = live_message.envelope(correlation_id=message.headers.correlation_id,\n                                              response_required=False).with_status(200)\n    # send the reply\n    self.reply(request_id, response_envelope)\n```\n\nFull example of the subscribing and handling messages can be found [here](examples/message_request_response_handling.py).\n\n## Logging\n\nThe default logger can be used in order to log events, regarding the client.\n\n```python\nclient.enable_logger(True)\n```\n\nAlternatively, an external logger can be also provided.\n\n```python\nlogging.basicConfig(level=logging.DEBUG)\nlogger = logging.getLogger(__name__)\nclient.enable_logger(True, logger)\n```\n\n**_NOTE:_** The logger must be enabled before connecting the client.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feclipse-ditto%2Fditto-clients-python","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Feclipse-ditto%2Fditto-clients-python","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feclipse-ditto%2Fditto-clients-python/lists"}