Annotated and other specialised dictionaries for Python
Project description
Dictation: Annotated Python Dictionaries
The Dictation library compliments Python's built-in dict data type by offering several
fully compatible dictionary subclasses:
dictationwhich adds support for annotations – a way to carry additional metadata within – yet separate from – the data held in the dictionary itself;attrdictwhich adds support for getting, setting and deleting dictionary items as though they were attributes;dottedictwhich adds support for getting, setting and deleting nested dictionary items via dotted item paths;lazydictwhich adds support for lazily loading dictionary items on demand through a callback.
As each of these specialised dictionary types are subclasses of the built-in dict type,
they should be useable as drop-in replacements for the dict type.
The dictation library name is a portmanteau of dic-tionary and anno-tation, inspired by the first of the dictionary subclasses, dictation, offered by the library.
Requirements
The Dictation library has been tested with Python 3.10, 3.11, 3.12, 3.13 and 3.14. The library is not expected to be compatible with Python 3.9 or earlier.
Installation
The Dictation library is available from PyPI so may be added to a project's dependencies
via its requirements.txt file or similar by referencing the Dictation library's name,
dictation, or the library may be installed directly into the local runtime environment
using pip install by entering the following command, and following any prompts:
$ pip install dictation
The Dictation Dictionary Type
The dictation dictionary type automatically assigns parent relationships to all child
dictionaries, which can be useful in some data processing scenarios, whether or not these
are used in addition to the library's annotation capabilities.
The ability to assign annotations, or keep track of parent relationships for child nodes of a nested dictionary structure can be useful where one can not modify the structure or data held in a dictionary, because doing so could render it incompatible for some uses.
The dictation dictionary class type's methods and properties are documented here, and an example of using the class can be found here.
The Attribute Dictionary Type
The attrdict adds support for getting, setting and deleting dictionary items as though
they were instance attributes. The attrdict also continues to provide access to the
dictionary items through the usual item access patterns and methods.
It is a subclass of the dictation dictionary type, so also offers the functionality of
the dictation dictionary type.
The attrdict dictionary class type's methods and properties are documented here, and an example of using the class can be found here.
The Dotted Dictionary Type
The dottedict adds support for getting, setting and deleting nested dictionary items
via dotted key paths. The key paths by default are specified as strings that use the dot
character (.) as the separator between the nested keys that define the path from the
root of the dictionary to the desired nested element, such as "a.b.c". The separator can
be changed if necessary by specifying the optional separator keyword argument to the
dottedict() class constructor when creating an instance of the class, and providing an
alternative string value to use as the separator. Key paths can also be specified as
arrays of keys, such as ["a", "b", "c"], instead which may be beneficial for some uses.
It is a subclass of the dictation dictionary type, so also offers the functionality of
the dictation dictionary type.
The dottedict dictionary class type's methods and properties are documented here, and an example of using the class can be found here.
The Lazy Dictionary Type
The lazydict provides support for lazily loading absent dictionary items via a callback
method – this can be especially useful where doing so involves a computationally expensive
or time-consuming operation, and where the data held by the initially absent items may not
be needed for every runtime use case that involves the dictionary and its data.
It is a subclass of the dictation dictionary type, so also offers the functionality of
the dictation dictionary type.
The lazydict dictionary class type's methods and properties are documented here, and an example of using the class can be found here.
Class Methods & Properties
The class methods and properties of the dictionary subclasses are detailed below.
The dictation Annotated Dictionary Class
The Dictation library's dictation class is a subclass of the built-in dict class, so
all of the built-in functionality of dict is available, as well as several additional
class methods and properties as documented below:
-
annotate(recursive: bool = False, **kwargs)– Theannotate()method can be used to assign one or more annotations to the currentdictationinstance provided as key-value pairs; these are held separately from and do not interfere with the actual data held in the dictionary. Therecursivekeyword is reserved for specifying if the annotations provided will be marked as being recursively available for the current node as well as for any nested child nodes, whenrecursiveis set toTrue– whenrecursiveis set toFalse(or simply when therecursiveargument is not specified), the annotations will only available for the current node. Additionally, theannotate()method returnsselfupon completion so calls toannotate()can be chained with calls to other class methods, such as theget()method. -
unannotate(name: str) -> dictation– Theunannotate()method provides support for removing a named annotation from the current node; it cannot remove any annotations that have been inherited from ancestors in the hierarchy; to remove a recursive annotation, it must be removed directly from thedictationancestor node it was assigned to. -
annotation(name: str, default: object = None, recursive: bool = True) -> object– Theannotation()method supports recursively obtaining a named annotation value. If the named annotation cannot be found, thedefaultvalue will be returned if one has been provided, and if not, theNonevalue will be returned. -
annotations (getter) -> dict[str, object]– Theannotationsgetter returns the annotations, if any, assigned to the currentdictationnode, or inherited from any ancestors, where those annotations were assigned and set as being recursively available. -
annotations (setter) <- dict[str, object]– Theannotationssetter supports assigning one or more annotations, specified as a dictionary of key-value pairs, to the currentdictationnode. Annotations applied via theannotationssetter only apply to the currentdictationnode as they are not assigned as being recursively available to any child nodes. If an annotation needs to be made available to the current node as well as recursively to any child nodes, it must be set via theannotate()method instead, which provides control over the recursive availability of the annotation being assigned. -
parent (getter) -> dictation | None– Theparentproperty returns a reference to the currentdictationinstance's parent, if available, otherwiseNoneis returned. -
set(key: object, value: object) -> dictation– Theset()method is a compliment to the built-indictclass'getmethod. Theset()method accepts the usual key and value as method keyword arguments, and assigns the value to the currentdictationinstance at the provided key. Additionally, theset()method returnsselfupon completion, so calls toset()can be chained with calls to other class methods, such as theannotate()method. -
data(metadata: bool = False, annotations: bool = False) -> dict– Thedata()method supports generating a dictionary representation of the dictation's data, as well as optionally including associated metadata such as the parent reference, any assigned annotation values, and typing information for each value. -
print(indent: int = 0)– Theprint()method supports generating a print-out of thedictationinstance's data as well as any annotations which can be useful for debugging and data visualisation purposes.
The attrdict Attribute-Access Dictionary Class
The Dictation library's attrdict class is a subclass of the dictation class, so
all of the functionality of dictation class, and is ultimately a subclass of the built
in dict class, so all of the built-in functionality of dict is available, as well as
several additional class methods and properties as documented below:
-
__getattr__(...)– the__getattr__()magic method provides support for accessing the dictionary items as attributes, via the dictionary item key name. This magic method should not be called directly, rather it is called when an attribute getter pattern is used in the code. The method accepts the following arguments: -
key(object) – (required) thekeyargument is used to specify the key for the item to attempt to retrieve from the dictionary. If the item is found, its value is returned otherwise anAttributeErrorexception will be raised. -
__setattr__(...)– the__setattr__()magic method provides support for setting dictionary item values via attribute access. This magic method should not be called directly, rather it is called when an attribute setter pattern is used in the code. The method accepts the following arguments: -
key(object) – (required) thekeyargument is used to specify the key for the item to add to the dictionary. -
value(object) – (required) thevalueargument is used to specify the value for the item that will be set at the specifiedkeywithin the dictionary. -
__delattr__(...)– the__delattr__()magic method provides support for deleting dictionary items via attribute access. This magic method should not be called directly, rather it is called when an attribute deletion pattern is used in the code. The method accepts the following arguments: -
key(object) – (required) thekeyargument is used to specify the key for the item to remove from the dictionary.
The dottedict Nested Access Dictionary Class
The Dictation library's dottedict class is a subclass of the dictation class, so all
of the functionality of dictation class, and is ultimately a subclass of the built in
dict class, so all of the built-in functionality of dict is available, as well as
several additional class methods and properties as documented below:
-
__contains__(...)(bool) – The__contains__()magic method provides support for checking if a dictionary item is available at the specified key path. This magic method should not be called directly, rather it is called when an item existence check via theinkeyword is used in the code. The method accepts the following arguments: -
key(object) – (required) thekeyargument is used to specify the key for the item to look up in the dictionary. If the item is found the method returnsTrueorFalseotherwise. -
__getitem__(...)(object) – The__getitem__()magic method provides support for getting a dictionary item at the specified key path, if it is present in the dictionary. This magic method should not be called directly, rather it is called when an item getter access pattern is used in the code. The method accepts the following arguments: -
key(object) – (required) thekeyargument is used to specify the key for the item to attempt to retrieve from the dictionary. If the item is found, its value is returned otherwise aKeyErrorexception will be raised. -
__setitem__(...)– The__setitem__()magic method provides support for setting a dictionary item via a dotted key path. This magic method should not be called directly, rather it is called when an item setter access pattern is used in the code. The method accepts the following arguments: -
key(object) – (required) thekeyargument is used to specify the key for the item to attempt to retrieve from the dictionary. If the item is found, its value is returned otherwise aKeyErrorexception will be raised. -
value(object) – (required) thevalueargument is used to specify the value for the item that will be set at the specifiedkeywithin the dictionary. -
__delitem__(...)– The__delitem__()magic method provides support for deleting a dictionary item via a dotted key path. This magic method should not be called directly, rather it is called when an item deletion is performed via thedelkeyword in the code. The method accepts the following arguments: -
key(object) – (required) thekeyargument is used to specify the key for the item to attempt to retrieve from the dictionary. If the item is found, its value is returned otherwise aKeyErrorexception will be raised. -
get(...)(object) – Theget()method overrides the standard dictionaryget()method to support accessing dictionary items via an optionally dotted key path. The method accepts the following arguments: -
key(object) – (required) thekeyargument is used to specify the key for the item to attempt to retrieve from the dictionary. If the item cannot be found, the method will return the specifieddefaultvalue if adefaultvalue has been specified orNone. -
default(object) – (optional) thedefaultargument can be used to specify the fallback default value that theget()method should return in the case that an item at the specified key path does not exist. If nodefaultargument is specified, theget()method will returnNone. -
has(...)(bool) – Thehas()method compliments theget()method to support determining if a dictionary item exists at an optionally dotted key path or not. The method accepts the following arguments: -
key(object) – (required) thekeyargument is used to specify the key for the item to attempt to retrieve from the dictionary. -
set(...)(lazydict) – Theset()method compliments the standard dictionaryget()method to support setting a dictionary item value at the specified key path. The method accepts the following arguments: -
key(object) – (required) thekeyargument is used to specify the key for the item to attempt to retrieve from the dictionary. If the item cannot be found, the method will return the specifieddefaultvalue if adefaultvalue has been specified orNone. -
value(object) – (required) thevalueargument is used to specify the value to set for the specifiedkey. -
unset(...)(lazydict) – Theunset()method compliments theset()method to support unsetting or deleting a dictionary item at the specified key path. The method accepts the following arguments: -
key(object) – (required) thekeyargument is used to specify the key for the item to attempt to retrieve from the dictionary. If the item cannot be found, the method will return the specifieddefaultvalue if adefaultvalue has been specified orNone.
The lazydict Lazy Loading Dictionary Class
The Dictation library's lazydict class is a subclass of the dictation class, so
all of the functionality of dictation class, and is ultimately a subclass of the built
in dict class, so all of the built-in functionality of dict is available, as well as
several additional class methods and properties as documented below:
-
__getitem__(...)– The__getitem__()magic method supports overriding the standard behaviour of the__getitem__()magic method to provide support for lazily loading missing dictionary items via the specified callback method. This magic method should not be called directly, rather it is called when an item getter access pattern is used in the code. The method accepts the following arguments: -
key(object) – (required) thekeyargument is used to specify the key for the item to look up in the dictionary. If the item is found the method returnsTrueorFalseotherwise. -
__setitem__(...)– The__setitem__()magic method supports overriding the standard behaviour of the__setitem__()magic method to provide support for keeping track of which dictionary keys are available, as this determines which key/values need to be lazy loaded or not. This magic method should not be called directly, rather it is called when an item setter access pattern is used in the code. The method accepts the following arguments: -
key(object) – (required) thekeyargument is used to specify the key for the item to attempt to retrieve from the dictionary. If the item is found, its value is returned otherwise aKeyErrorexception will be raised. -
value(object) – (required) thevalueargument is used to specify the value for the item that will be set at the specifiedkeywithin the dictionary. -
__delitem__(...)– The__delitem__()magic method supports overriding the standard behaviour of the__delitem__()magic method to provide support for keeping track of which dictionary keys are available, as this determines which key/values need to be lazy loaded or not. This magic method should not be called directly, rather it is called when an item deletion is performed via thedelkeyword in the code. The method accepts the following arguments: -
key(object) – (required) thekeyargument is used to specify the key for the item to look up in the dictionary. If the item is found the method returnsTrueorFalseotherwise. -
get(...)(object) – Theget()method overrides the standard dictionaryget()method to support lazily loading dictionary items. The method accepts the following arguments: -
key(object) – (required) thekeyargument is used to specify the key for the item to attempt to retrieve from the dictionary. If the item cannot be found, the method will return the specifieddefaultvalue if adefaultvalue has been specified orNone. -
default(object) – (optional) thedefaultargument can be used to specify the fallback default value that theget()method should return in the case that an item at the specified key path does not exist and cannot be loaded or is intentionally not loaded by the callback lazy loader method. If nodefaultargument is specified, theget()method will returnNone. -
has(...)(bool) – Thehas()method compliments theget()method to support determining if a dictionary item exists or not. The method accepts the following arguments: -
key(object) – (required) thekeyargument is used to specify the key for the item to attempt to retrieve from the dictionary. -
set(...)(lazydict) – Theset()method compliments the standard dictionaryget()method to support setting a dictionary item value at the specified key path. The method accepts the following arguments: -
key(object) – (required) thekeyargument is used to specify the key for the item to attempt to retrieve from the dictionary. If the item cannot be found, the method will return the specifieddefaultvalue if adefaultvalue has been specified orNone. -
value(object) – (required) thevalueargument is used to specify the value to set for the specifiedkey. -
unset(...)(lazydict) – Theunset()method compliments theset()method to support unsetting or deleting a dictionary item at the specified key path. The method accepts the following arguments: -
key(object) – (required) thekeyargument is used to specify the key for the item to attempt to retrieve from the dictionary. If the item cannot be found, the method will return the specifieddefaultvalue if adefaultvalue has been specified orNone.
The dictation Attributed Dictionary Usage Demonstration
To use the Dictation library, simply import it and use the library's dictation class
as a replacement of, or compliment to, the built-in dict class:
from dictation import dictation
# Create a new `dictation` class instance with example data and add a few annotations:
sample = dictation(a=1, b=2, c=3).annotate(x=4, y=5)
# Check that the data held by the `dictation` instance is as expected; note that as
# the `dictation` class is a subclass of the `dict` class, that the two assertions below
# comparing against another `dictation` instance as well as a `dict` instance are valid:
assert sample == dictation(a=1, b=2, c=3)
assert sample == dict(a=1, b=2, c=3)
# Check that the annotation data held by the `dictation` instance is as expected; note
# that the annotations are held completely separately from the dictionary's data:
assert sample.annotations == dictation(x=4, y=5)
assert sample.annotations == dict(x=4, y=5)
# Modify the example annotation, "y", and add an annotation, "z", making both recursive:
sample.annotate(y=0, z=6.789, recursive=True)
# Check that the updates to the annotations are as expected:
assert sample.annotations == dictation(x=4, y=0, z=6.789)
# Attempt to obtain a named annotation; this works like the `dict` class' `get` method
# whereby if the annotation is found, it's value will be returned, otherwise the default
# value, if specified, will be returned, otherwise `None` will be returned instead:
assert sample.annotation("z") == 6.789
# An annotation named "v" does not exist, so the provided default is returned:
assert sample.annotation("v", default=8) == 8
# An annotation named "v" does not exist, nor is there a default, so `None` is returned:
assert sample.annotation("v") is None
# Add a new child dictionary to the current `dictation` instance, note that the child
# dictionary will be converted to a new `dictation` instance as will any of its nested
# child dictionaries:
sample["d"] = dict(e=5, f=6)
assert isinstance(sample["d"], dict)
assert isinstance(sample["d"], dictation)
# Check that the `sample` dictionary has the expected structure and data:
assert sample == dict(a=1, b=2, c=3, d=dict(e=5, f=6))
# Check that the nested dictionary, "d", has the expected annotations; as no annotations
# have currently been assigned directly to the nested dictionary "d", it will only have
# inherited recursive annotations assigned to its parent and their parents. As per this
# example code, it currently means that the inherited annotations consist of "y" and "z"
# which were assigned to the parent dictionary, `sample`, and as they were both marked
# as recursive annotations, they are available to any nested children, including to "d":
assert sample["d"].annotations == dict(y=0, z=6.789)
# The `dictation` library also supports assigning annotations as attributes; annotations
# added as attributes cannot use the same name as any of the class' inherent attributes,
# properties or methods however; attempting to assign an attribute using the name of an
# inherent class attribute will raise an exception. So long as the annotation names are
# distinct, annotations can easily be assigned and retrieved using attribute accessors:
sample.greeting = "hello"
# Check that the annotation, "greeting", has the expected value
assert sample.greeting == "hello"
# Annotations assigned via attributes are stored identically as annotations assigned to
# a `dictation` instance in any other way, so they can all be accessed interchangeably:
assert sample.annotation("greeting") == "hello"
# Annotations assigned via the `annotate()` method can also be accessed as attributes:
assert sample.x == 4
assert sample.y == 0
assert sample.z == 6.789
# All annotations assigned to a node can be accessed as a dictionary representation via
# the `annotations` property, which returns a `dict` instance holding the annotations:
assert sample.annotations == dict(x=4, y=0, z=6.789, greeting="hello")
# Regardless of how annotations are assigned to the `dictation` instance, they can be
# accessed, modified or removed by any of the other methods; for example, annotations
# can be removed using the `unannotate()` method, which returns `self` on completion
# so can be chained:
assert sample.unannotate("y").annotations == dict(x=4, z=6.789, greeting="hello")
# The `del` language keyword can also be used to remove previously assigned annotations:
del sample.z
assert sample.annotations == dict(x=4, greeting="hello")
⚠️ Please Note: Like any subclass of the built-in dict type, instances of the dictation
class can not be created directly via Python's dictionary-literal {...} syntax, rather
they must be instantiated using the dictation class constructor. One can however wrap
any {} dictionary literal, as well as variables holding a dict with a dictation
class constructor to convert any regular dict to a dictation class instance; this is
also true for the other dict subclasses offered by the library, such as the attrdict
or dottedict subclasses.
from dictation import dictation
# The Python dictionary-literal syntax can only create `dict` instances:
sample = {"a": 1, "b": 2, "c": 3}
assert isinstance(sample, dictation) is False
assert isinstance(sample, dict) is True
assert sample == {"a": 1, "b": 2, "c": 3}
# So the `dictation` class constructor must be used to create all `dictation` instances,
# however, the `dictation` constructor can take a dictionary literal as input:
sample = dictation({"a": 1, "b": 2, "c": 3})
assert isinstance(sample, dictation) is True
assert isinstance(sample, dict) is True
assert sample == {"a": 1, "b": 2, "c": 3}
# Furthermore, variables holding regular `dict` values, whether created via the literal
# syntax or via the `dict` class constructor syntax...
sample = {"x": 7, "y": 8, "z": 9}
assert isinstance(sample, dictation) is False
assert isinstance(sample, dict) is True
assert sample == {"x": 7, "y": 8, "z": 9}
sample = dict(sample)
assert isinstance(sample, dictation) is False
assert isinstance(sample, dict) is True
assert sample == {"x": 7, "y": 8, "z": 9}
# ...can be passed to the `dictation` class constructor to cast to a `dictation` class:
sample = dictation(sample)
assert isinstance(sample, dictation) is True
assert isinstance(sample, dict) is True
assert sample == {"x": 7, "y": 8, "z": 9}
One may also pass additional key-value pairs to the dictation class constructor during
casting. These additional key-value pairs will overwrite any matching existing keys with
the newly assigned values, as well as adding new key-value pairs to the dictionary for
keys that have not yet been defined:
from dictation import dictation
base = dict(a=1, b=2, c=3)
assert base == dict(a=1, b=2, c=3)
sample = dictation(base, c=4, x=7, y=8, z=9) # "c" is being redefined with a value of 4
assert sample == dictation(a=1, b=2, c=4, x=7, y=8, z=9)
assert sample == dict(a=1, b=2, c=4, x=7, y=8, z=9)
The attrdict Attribute-Access Dictionary Usage Demonstration
To use the attrdict dictionary class as a replacement of, or compliment to, the
built-in dict class, simply import it from the dictation library as follows, and use
it to support regular and/or attribute-style access to the dictionary's items:
from dictation import attrdict
# Create a new instance of the attrdict
sample = attrdict({"a": 1, "b": 2, "c": 3})
# Access existing items via attribute-access, dictionary items and getter methods:
assert sample.a == 1
assert sample["a"] == 1
assert sample.get("a") == 1
assert sample.b == 2
assert sample["b"] == 2
assert sample.get("b") == 2
assert sample.c == 3
assert sample["c"] == 3
assert sample.get("c") == 3
# Add a new item, "d", to the dictionary
sample.d = 4
assert sample.d == 4
assert sample["d"] == 4
assert sample.get("d") == 4
# Remove item "a" from the dictionary
assert "a" in sample
del sample["a"]
assert not "a" in sample
The dottedict Attribute-Access Dictionary Usage Demonstration
To use the dottedict dictionary class as a replacement of, or compliment to, the
built-in dict class, simply import it from the dictation library as follows, and use
it to support regular and/or attribute-style access to the dictionary's items:
from dictation import dottedict
# Create a new instance of the dottedict
sample = dottedict({"a": {"b": {"c": 123} } })
# Access the existing dictionary items using dictionary item access:
assert sample["a"] == {"b": {"c": 123}}
assert sample["a"]["b"] == {"c": 123}
assert sample["a"]["b"]["c"] == 123
# Access the existing dictionary items using dictionary item access with dotted keys:
assert sample["a.b"] == {"c": 123}
assert sample.get("a.b") == {"c": 123}
assert sample["a.b.c"] == 123
assert sample.get("a.b.c") == 123
# Access the nested dictionary items via a list of keys
assert sample[["a", "b", "c"]] == 123
assert sample.get(["a", "b", "c"]) == 123
# Add a new item, "a.b.d", to the dictionary
sample["a.b.d"] = 456
# Access the new dictionary item through the various supported patterns
assert sample["a"]["b"]["d"] == 456
assert sample["a.b.d"] == 456
assert sample.get("a.b.d") == 456
assert sample[["a", "b", "d"]] == 456
assert sample.get(["a", "b", "d"]) == 456
# Check the dictionary structure is as expected after the addition
assert sample == {"a": {"b": {"c": 123, "d": 456}}}
# Remove item "a.b.c" from the dictionary
assert "a.b.c" in sample
del sample["a.b.c"]
assert not "a.b.c" in sample
# Check the dictionary structure is as expected after the removal
assert sample == {"a": {"b": {"d": 456}}}
The lazydict Attribute-Access Dictionary Usage Demonstration
To use the lazydict dictionary class as a replacement of, or compliment to, the
built-in dict class, simply import it from the dictation library as follows, and use
it to support regular and/or attribute-style access to the dictionary's items:
from dictation import lazydict
# Callback methods can have any name but they must accept 'key', 'parent' and 'calltype'
# arguments, which specify the missing dictionary item key that triggered the callback,
# a reference to a read-only copy of the parent dictionary, and the type of dictionary
# access call type that triggered the callback, which will be either "has" or "get", for
# calls relating to checking if the dictionary "has" an item or not, such as via "in" or
# for calls relating to getting dictionary items via item access or getter method calls:
def callback(key: str, parent: lazydict, calltype: str) -> dict | None:
"""Simple lazy loader callback that returns a dictionary for the key specified, and
uses the key for the value also. The callback must return a dictionary or None, but
does not need to just return a dictionary for the current key, instead callbacks
can run any operation needed to source, build, format, and return a dictionary value consisting of one or more keys and associated values. A callback can also return no
value by returning None which results in the lazydict remaining the same."""
return {key: key}
# Create a new instance of the lazydict
sample = lazydict({"a": 1, "b": 2, "c": 3}, callback=callback)
# Access the existing dictionary items using dictionary item access
assert sample["a"] == 1
assert sample["b"] == 2
assert sample["c"] == 3
# Check the dictionary structure is as expected
assert sample == {"a": 1, "b": 2, "c": 3}
assert not "d" in sample
# Attempt to access "d", which does not currently exist, but will be added through the
# callback method, that in this trivial example creates an item using the key, "d", and
# assigns the key as the value for demonstration purposes; the callback method could add
# any number of dictionary items or none at all during any given callback call – it just
# depends on the use case and the data needs of the application; the callback method is
# only be called however when an attempt is made to access keys that do not yet exist:
assert sample["d"] == "d"
assert "d" in sample
# Check the dictionary structure is as expected after the addition of item "d"
assert sample == {"a": 1, "b": 2, "c": 3, "d": "d"}
Contributing & Local Development
To carry out development of the Dictation library, create a fork of the repository from the GitHub account, then clone a copy of the fork to the local machine for development and testing:
$ cd path/to/local/development/directory
$ git clone git@github.com:bluebinary/dictation.git
Then create a new feature/development branch, using a descriptive name for the branch:
$ cd path/to/local/development/directory/dictation
$ git checkout -b new_feature_branch
Code Linting
The Dictation library adheres to the code formatting specifications detailed in PEP-8,
which are verified and applied by the Black code formatting tool. When code changes
are made to the library, one needs to ensure that the code conforms to these code
formatting specifications. To simplify this, the provided Dockerfile creates an image
that supports running Black against the latest version of the code, and will report if
any issues are found. To run the code formatting checks, perform the following commands,
which will build the Docker image and then run the formatting checks:
$ docker compose build
$ docker compose run black
If any code formatting issues are found, they will be reported by Black. It is also
possible to run Black so that it will automatically reformat the affected files; this
can be achieved as follows, by passing the --verbose flag, which allows Black to
report which files have been reformatted:
$ docker compose run black --verbose
The above will reformat any library source and unit test files that contain formatting issues, and will report which changes are made.
Unit Tests
The Dictation library includes a suite of comprehensive unit tests which ensure that the
library functionality operates as expected. The unit tests were developed with and are
run via pytest.
To ensure that the unit tests are run within a predictable runtime environment where all
of the necessary dependencies are available, a Docker image is
created within which the tests are run. To run the unit tests, ensure Docker and Docker
Compose are installed, and run the commands
listed below, which will build the Docker image via docker compose build and then run
the tests via docker compose run tests – the output of the tests will be displayed:
$ docker compose build
$ docker compose run tests
To run the unit tests with optional command line arguments being passed to pytest,
append the relevant arguments to the docker compose run tests command, as follows, for
example passing -v to enable verbose output or -s to print standard output:
$ docker compose run tests -v -s
See the documentation for PyTest regarding the available optional command line arguments.
Copyright & License Information
Copyright © 2024–2026 Daniel Sissman; licensed under the MIT License.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file dictation-1.0.1.tar.gz.
File metadata
- Download URL: dictation-1.0.1.tar.gz
- Upload date:
- Size: 39.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
db2fc54f2fa6d3f2e2519dddd3b1e9bd2b855e74311f922d1afa4f74f47dc412
|
|
| MD5 |
8a19bfbd029d0e737aad5257d0ddad2a
|
|
| BLAKE2b-256 |
245053436ecdc2ea8113486789f8ec7be9a1c9dd0a486e44c394db47245b080b
|
Provenance
The following attestation bundles were made for dictation-1.0.1.tar.gz:
Publisher:
python-publish.yml on bluebinary/dictation
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
dictation-1.0.1.tar.gz -
Subject digest:
db2fc54f2fa6d3f2e2519dddd3b1e9bd2b855e74311f922d1afa4f74f47dc412 - Sigstore transparency entry: 1399469062
- Sigstore integration time:
-
Permalink:
bluebinary/dictation@0ad19d82487a9bafcd7656543eff3b01e8ac7fdf -
Branch / Tag:
refs/tags/v1.0.1 - Owner: https://github.com/bluebinary
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@0ad19d82487a9bafcd7656543eff3b01e8ac7fdf -
Trigger Event:
release
-
Statement type:
File details
Details for the file dictation-1.0.1-py3-none-any.whl.
File metadata
- Download URL: dictation-1.0.1-py3-none-any.whl
- Upload date:
- Size: 22.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e8ca5327f0e8e4274a6520bd1c0c6e2a21514c0bb0632ff8a561e9638e8d655f
|
|
| MD5 |
a7fc6dab8970e140ab71851132727d53
|
|
| BLAKE2b-256 |
bd5c8e5ab370f2ecf22906a9b0803c28cec1b6f6b6bb84a1bbeb0e6888a09ed5
|
Provenance
The following attestation bundles were made for dictation-1.0.1-py3-none-any.whl:
Publisher:
python-publish.yml on bluebinary/dictation
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
dictation-1.0.1-py3-none-any.whl -
Subject digest:
e8ca5327f0e8e4274a6520bd1c0c6e2a21514c0bb0632ff8a561e9638e8d655f - Sigstore transparency entry: 1399469067
- Sigstore integration time:
-
Permalink:
bluebinary/dictation@0ad19d82487a9bafcd7656543eff3b01e8ac7fdf -
Branch / Tag:
refs/tags/v1.0.1 - Owner: https://github.com/bluebinary
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@0ad19d82487a9bafcd7656543eff3b01e8ac7fdf -
Trigger Event:
release
-
Statement type: