Skip to main content

Little helper for handling entity clusters

Project description

eche logo

Actions Status Documentation Status Stable python versions Ruff

Usage

Eche provides a ClusterHelper class to conveniently handle entity clusters.

  from eche import ClusterHelper
  ch = ClusterHelper([{"a1", "b1"}, {"a2", "b2"}])
  print(ch.clusters)
  {0: {'a1', 'b1'}, 1: {'a2', 'b2'}}

Add an element to a cluster

  ch.add_to_cluster(0, "c1")
  print(ch.clusters)
  {0: {'a1', 'b1', 'c1'}, 1: {'a2', 'b2'}}

Add a new cluster

  ch.add({"e2", "f1", "c3"})
  print(ch.clusters)
  {0: {'a1', 'b1', 'c1'}, 1: {'a2', 'b2'}, 2: {'f1', 'e2', 'c3'}}

Remove an element from a cluster

  ch.remove("b1")
  print(ch.clusters)
  {0: {'a1', 'c1'}, 1: {'a2', 'b2'}, 2: {'f1', 'e2', 'c3'}}

The __contains__ function is smartly overloaded. You can check if an entity is in the ClusterHelper:

  "a1" in ch
  # True

If a cluster is present

  {"c1","a1"} in ch
  # True

And even if a link exists or not

  ("f1","e2") in ch
  # True
  ("a1","e2") in ch
  # False

To know the cluster id of an entity you can look it up with

  print(ch.elements["a1"])
  0

To get members of a cluster either use

  print(ch.members(0))
  {'a1', 'b1', 'c1'}

or simply

  print(ch[0])
  {'a1', 'b1', 'c1'}

More functions can be found in the Documentation.

Installation

Simply use pip for installation:

pip install eche

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

eche-0.2.0.tar.gz (11.5 kB view details)

Uploaded Source

Built Distribution

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

eche-0.2.0-py3-none-any.whl (10.2 kB view details)

Uploaded Python 3

File details

Details for the file eche-0.2.0.tar.gz.

File metadata

  • Download URL: eche-0.2.0.tar.gz
  • Upload date:
  • Size: 11.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.3.1 CPython/3.10.6 Linux/5.19.0-38-generic

File hashes

Hashes for eche-0.2.0.tar.gz
Algorithm Hash digest
SHA256 ac81e122e3e0821c4c27764eb5516538f67dd6199e7d415cfa9a8578adcda434
MD5 a2d5d0fc5ad1070a498023917b799ec1
BLAKE2b-256 6e053aa30b027f6a8b94538590a5ebaa836e9031ffba14838cbb8cb37e8350ec

See more details on using hashes here.

File details

Details for the file eche-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: eche-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 10.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.3.1 CPython/3.10.6 Linux/5.19.0-38-generic

File hashes

Hashes for eche-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 adab47d18d595a3487bccb173ce7d87dfd8fb0b9be84356977e3badb0be614b6
MD5 0200c49c47181ff23ab1d36d54800c08
BLAKE2b-256 a3213756ea5777b7464bffcd510dd7ea6bd644c724531b0f3945395cefa07de7

See more details on using hashes here.

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