A small collection to index objects using tags. Type-safe.
Installation
pip install countertype
Usage
You can add any hashable items into the collection using tags. Let’s add two string values, "ev1", and "ev2". Each element must have at least one tag, called id, that identifies that object. Ids must be unique inside the collection, and can’t be changed later. Regular tags can be updated.
from countertype import CounterType
ct: CounterType[str] = CounterType()
ct.put(
"ev1",
id="1",
state="RUNNING",
parent="ev_parent",
)
ct.put(
"ev2",
id="2",
state="STOPPED",
parent="ev_parent",
)
To find elements we can search by any of the defined tags, using the **kw:
Let’s find all the elements with the state tag set to "STOPPED":
ct.find_all(state="STOPPED")
This will return an iterable with all the matching elements.
To find a single element, we can fetch it again, as an Optional:
ct.find(state="STOPPED")
Multiple tags are also supported, and will intersect the potential matches:
ct.find(state="STOPPED", parent_id="123")
Updating tags for existing items is also possible, by using the item id. Of course, multiple tags could be updated.
ct.update(id="1", state="PROCESSING")
To remove an element from the collection, pass its id in the remove function:
ct.remove(id="1")
Metadata
Release files for countertype 1.2.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| countertype-1.2.2.tar.gz | 3.7 kB | Details |
Release files / countertype-1.2.2.tar.gz
| Download URL | countertype-1.2.2.tar.gz |
|---|---|
| Size | 3.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
eaa25c85ba0a422448e6e101587cbe5431270e77b62a982a75b9f6c2e6085c15
|
|
BLAKE2b-256 checksum How to use checksums |
2e609c9ca00f7851bf67b6d85df61dd1de258dbb0e14f8bb5c92349440918b10
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
Python-urllib/3.8
|