Skip to main content

gloss

Gloss (short for glossary) is a different kind of dictionary. All values also automatically become keys and so can be looked up in the Gloss to find its corresponding 'key'. This makes it easy to lookup and maintain one-to-one relationships such as a label to a certain magnitude.

Gloss is a MutableMapping and supports all the same methods that dict does.

Examples

from gloss import Gloss

example = Gloss()
example["stdin"] = 0
example.update({"stdout": 1, "stderr": 2})
print(example)
#Gloss({"stdin": 0, "stdout": 1, "stderr": 2})
print(example[1], "goes to" example["stderr"])
#stdout goes to 2
example[3] = "config.toml"
example[1] = "shell pipe"
print(example)
#Gloss({"stdin": 0, "stderr": 2, "config.toml": 3, "shell pipe": 1})
print([fd_or_desc for fd_or_desc in example])
#["stdin", "stderr", "config.toml", "shell pipe", 0, 1, 2, 3]

As both the key and value are gettable items from the Gloss and are indistinguishable once added, term is the preferred name for items in a Gloss, and a term pair is the 1-1 mapping each term belongs to.

Differences from Enum

Enum is a wonderful data structure that also supports 1-1 mappings and it's already built into Python. However, these limitations of Enums are solved by Gloss:

  • enum members are static. They are defined all at once in the class and their values cannot change. A Gloss on the other hand can be added to, altered, even have members deleted or popped, all at runtime
  • Accessing Enum member names and their values are different operations. Looking up a member by name is done with either dot dereference or getitem; looking up a member by value is done with a call. With a Gloss you don't have to know which side of the mapping your key is on (if there even is a distinction to the mapping), it is all done by getitem
  • One side of an enum mapping must be a string. Because member names are attributes they must follow Python identifier naming rules. In a Gloss, all terms may be any hashable object

Differences from Dict

While the classic dict solves some of the limitations of using an Enum, primarily being mutable at runtime, it is not a 1-1 mapping.

  • enforcing uniqueness among dict values is a lot of extra work
  • looking up a dict value is O(n). Therefore so is updating, deleting, popping, etc that value. Searching a Gloss for any term is O(1) time
  • updating any term in a Gloss takes a single operation

Metadata

Release files for gloss 1.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for gloss 1.3.0
File Size Uploaded Provenance
gloss-1.3.0.tar.gz 4.4 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for gloss 1.3.0
File Interpreter ABI Platform
gloss-1.3.0-py3-none-any.whl Python 3 none any Details

Total release size: 9.3 kB

Release files / gloss-1.3.0.tar.gz

Download URL gloss-1.3.0.tar.gz
Size 4.4 kB
Tags Source
SHA-256 checksum
How to use checksums
9c99887aa36f16a8bd190deeb2b47dfa850d4bff1c3a45056b16bd64631fcd44
BLAKE2b-256 checksum
How to use checksums
0305d7599dcf5ab73d00e6bca16c51e80b42e058502ccb296a1f1ddbe6d3fb2e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.7.3

Release files / gloss-1.3.0-py3-none-any.whl

Download URL gloss-1.3.0-py3-none-any.whl
Size 4.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3621d9b0e904ce6c4e9d6691ca63d4c7f6696e8d1a4611c439faba481956a150
BLAKE2b-256 checksum
How to use checksums
a6767bd0f1515f147787bd662baff6a840d9d96ad844717fbec5365bd0621185
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.7.3

Security for gloss 1.3.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.3.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page