WHAT
Lexicon is a simple collection of Python dict subclasses providing extra power:
AliasDict, a dictionary supporting both simple and complex key aliasing:
Alias a single key to another key, so that e.g. mydict['bar'] points to mydict['foo'], for both reads and writes.
Alias a single key to a list of other keys, for writing only, e.g. with active_groups = AliasDict({'ops': True, 'biz': True, 'dev': True, 'product': True}) one can make an alias 'tech' mapping to ('ops', 'dev') and then e.g. active_groups['tech'] = False.
Aliasing is recursive: an alias pointing to another alias will behave as if it points to the other alias’ target.
AttributeDict, supporting attribute read & write access, e.g. mydict = AttributeDict({'foo': 'bar'}) exhibits mydict.foo and mydict.foo = 'new value'.
Lexicon, a subclass of both of the above which exhibits both sets of behavior.
HOW
Regular use:
pip install lexicon
from lexicon import Lexicon (or one of the superclasses)
Use as needed.
Development/hacking/test suite:
- Install dev dependencies via any of the following:
pip install --group dev (assumes pip >= 25.1)
uv sync
anything else that understands PEP 735 dependency groups
inv test (or inv --list to see other dev tasks)
API
AliasDict
In all examples, 'myalias' is the alias and 'realkey' is the “real”, unaliased key.
alias(from_'myalias', to='realkey'): Alias myalias to realkey so d['myalias'] behaves exactly like d['realkey'] for both reads and writes.
from_ is the first keyword argument, but typically it can be omitted and still reads fine. See below examples for this usage. See below for details on how an alias affects other dict operations.
alias('myalias', to=('realkey', 'otherrealkey')): Alias myalias to both realkey and otherrealkey. As you might expect, this only works well for writes, as there is never any guarantee that all targets of the alias will contain the same value.
unalias('myalias'): Removes the myalias alias; any subsequent reads/writes to myalias will behave as normal for a regular dict.
'myalias' in d (aka __contains__): Returns True when given an alias, so if myalias is an alias to some other key, dictionary membership tests will behave as if myalias is set.
del d['myalias'] (aka __delitem__): This effectively becomes del d['realkey'] – to remove the alias itself, use unalias().
del d['realkey']: Deletes the real key/value pair (i.e. it calls dict.__del__) but doesn’t touch any aliases pointing to realkey.
As a result, “dangling” aliases pointing to nonexistent keys will raise KeyError on access, but will continue working if the target key is repopulated later.
Caveats:
Because of the single-key/multi-key duality, AliasDict is incapable of honoring non-string-type keys when aliasing (it must test isinstance(key, basestring) to tell strings apart from non-string iterables).
AliasDict instances may still use non-string keys, of course – it just can’t use them as alias targets.
AttributeDict
d.key = 'value' (aka __setattr__): Maps directly to d['key'] = 'value'.
d.key (aka __getattr__): Maps directly to d['key'].
del d.key (aka __delattr__): Maps directly to del d['key'].
Collisions between “real” or pre-existing attributes, and attributes-as-dict-keys, always results in the real attribute winning. Thus it isn’t possible to use attribute access to access e.g. d['get'].
Lexicon
Lexicon subclasses from AttributeDict first, then AliasDict, with the end result that attribute access will honor aliases. E.g.:
d = Lexicon() d.alias(‘myalias’, to=’realkey’) d.myalias = ‘foo’ print d.realkey # prints ‘foo’
Metadata
Release files for lexicon 3.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| lexicon-3.0.0.tar.gz | 10.2 kB | Without provenance | Details for lexicon-3.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| lexicon-3.0.0-py3-none-any.whl | Python 3 | none | any | Details for lexicon-3.0.0-py3-none-any.whl |
Total release size: 16.8 kB
Release files / lexicon-3.0.0.tar.gz
| Download URL | lexicon-3.0.0.tar.gz |
|---|---|
| Size | 10.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
fb4d9a382f266d2fe2c72d903b7ce0dd2988ab3878cd9590e2c02212f8094869
|
|
BLAKE2b-256 checksum How to use checksums |
2b0d835398e7d9ed4ec205bccafb16f830952b8c2c96ff53f244a4c7f0e5b33a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.3
|
Release files / lexicon-3.0.0-py3-none-any.whl
| Download URL | lexicon-3.0.0-py3-none-any.whl |
|---|---|
| Size | 6.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
25f1bfe961d141d8bd03194ae75360207117f2ee04607df6c06a3c96025759d6
|
|
BLAKE2b-256 checksum How to use checksums |
c65a9390d11728d0dd249ce4fff1e389246fa6313d1a775ff460a3dc0bfb2c24
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.3
|
Security for lexicon 3.0.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.