Skip to main content

Eclipse Ditto Python Client

Project description

Eclipse Ditto Client

Eclipse Ditto Project - https://eclipse.dev/ditto/index.html

This repository is the python client generated using Microsoft Kiota (https://github.com/microsoft/kiota-python) and a CLI based client.

Install

uv add ditto-client

Running Ditto

A sample docker compose is provided as part of this repository.

You must run the ditto services outside the devcontainer as they consume lot of resources.

# outside your devcontainer (i.e. on your host)
# at <your_path>/ditto-client dir
docker compose -f assets/ditto/docker-compose.yaml up

Usage

auth_provider = BasicAuthProvider(user_name=_USERNAME, password=_PASSWORD)

request_adapter = HttpxRequestAdapter(auth_provider)
request_adapter.base_url = "http://host.docker.internal:8080"

ditto_client = DittoClient(request_adapter)

response = await ditto_client.api.two.things.get()

Default setup for Ditto uses Ngix with basic authentication. A custom authentication provider has been included in the library to support it. See BasicAuth Provider.

See examples/basic.py for the full usage

Usage - CLI

The Ditto client includes a comprehensive CLI for interacting with Eclipse Ditto services. The CLI provides the following commands:

Command Group Description
policy Manage access policies
thing Manage things (digital twins)
search Search for things
permission Check permissions
devops DevOps operations (logging, config, connection)

Global Configuration

The CLI uses the following environment variables, you can set it as per your environment:

export DITTO_BASE_URL="http://host.docker.internal:8080"
export DITTO_USERNAME="ditto"
export DITTO_PASSWORD="ditto"
export DITTO_DEVOPS_USERNAME="devops"
export DITTO_DEVOPS_PASSWORD="foobar"

Policy Management

Create a new policy.

# Create a new policy
ditto-client policy create "my.sensors:sensor-policy" examples/cli-examples/policy.json

Retrieve a specific policy by ID.

# Get a policy
ditto-client policy get "my.sensors:sensor-policy"

List policy entries.

# List all policy entries
ditto-client policy entries "my.sensors:sensor-policy"

Delete policy.

# Delete a policy
ditto-client policy delete "my.sensors:sensor-policy"

Things Management

Create a new thing.

# Make sure to create the policy (my.sensors:sensor-policy) See above example
# Create a new thing
ditto-client thing create "my.sensors:sensor-001" examples/cli-examples/thing.json

List all things with optional filtering.

# List all things
ditto-client thing list

# List things with specific fields
ditto-client thing list --fields "thingId,attributes"

# List specific things by ID
ditto-client thing list --ids "my.sensors:sensor-001"

Retrieve a specific thing by ID.

# Get a specific thing
ditto-client thing get "my.sensors:sensor-001"

# Get a specific revision of a thing
ditto-client thing get "my.sensors:sensor-001" --revision 1

Update a thing using JSON file.

# Update a thing
ditto-client thing update "my.sensors:sensor-001" examples/cli-examples/thing.json

Compare current thing with historical revision.

# Compare current state with revision 1
ditto-client thing diff "my.sensors:sensor-001" 1

Delete a thing.

# Delete a thing
ditto-client thing delete "my.sensors:sensor-001"

Search Operations

Refer below documentation to understand RQL syntax: https://eclipse.dev/ditto/1.5/basic-rql.html

Search for things using RQL (Resource Query Language).

# Search all things
ditto-client search query

# Search with filter
ditto-client search query --filter 'eq(attributes/location,"Kitchen")'

# Search with size limit and sorting
ditto-client search query --option "size(3),sort(+thingId)"

# Search in specific namespaces
ditto-client search query --namespaces "my.sensors"

Count things matching search criteria.

# Count all things
ditto-client search count

# Count things with filter
ditto-client search count --filter 'eq(attributes/location,"Kitchen")'

Connection Management (DevOps)

Create a new connection.

# Create a connection
ditto-client devops connection create "new-connection" examples/cli-examples/connection.json

List all connections.

# List all connections
ditto-client devops connection list

# List with specific fields
ditto-client devops connection list --fields "id,connectionStatus"

Retrieve a specific connection by ID.

# Get a connection
ditto-client devops connection get "new-connection"

# Get with specific fields
ditto-client devops connection get "new-connection" --fields "id,status"

Delete a connection.

# Delete a connection
ditto-client devops connection delete "new-connection"

Configuration Management (DevOps)

Retrieve service configuration.

# Get all configuration
ditto-client devops config get

Logging Management (DevOps)

Retrieve logging configuration.

# Get logging configuration
ditto-client devops logging get

# Get module-specific config
ditto-client devops logging get --module-name "gateway"

Update logging configuration.

# Update logging configuration
ditto-client devops logging update examples/cli-examples/logging.json

Permission Management (DevOps)

Check permissions on specified resources.

# Check permissions
ditto-client permission check examples/cli-examples/permission.json

Get current user information.

# Get current user info
ditto-client whoami

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ditto_client-0.3.0.tar.gz (214.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ditto_client-0.3.0-py3-none-any.whl (404.7 kB view details)

Uploaded Python 3

File details

Details for the file ditto_client-0.3.0.tar.gz.

File metadata

  • Download URL: ditto_client-0.3.0.tar.gz
  • Upload date:
  • Size: 214.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for ditto_client-0.3.0.tar.gz
Algorithm Hash digest
SHA256 0afd3bbed38a1474464aa234bb770905ff72236e9f8c697f26d0be0ff0187468
MD5 b3f2a62166b9eb10b7f195a5d16c5701
BLAKE2b-256 4a22999edff0a1a31747f46d36fee4d3137568db7c8ea9fb465cae27c3db3c33

See more details on using hashes here.

Provenance

The following attestation bundles were made for ditto_client-0.3.0.tar.gz:

Publisher: publish.yaml on ksachdeva/ditto-client

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ditto_client-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: ditto_client-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 404.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for ditto_client-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 01e48f8e9da768bb0b8280f7a277968474dfbc7126fabda0306f5d90d1c0886a
MD5 046427cddbfa081e8de066adcdbcc504
BLAKE2b-256 80dfda9af98273df30c1e31b27f7904dae44788b4fa15db1dd5d856a714ecdf2

See more details on using hashes here.

Provenance

The following attestation bundles were made for ditto_client-0.3.0-py3-none-any.whl:

Publisher: publish.yaml on ksachdeva/ditto-client

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page