Lookups¶
Lookups finds available Python objects by type and lets you observe changes in what an application exposes.
Find your first objects Install Lookups
from lookups import fixed
available = fixed("Preview", 42)
print(available.lookup(str))
A query returns an object matching the searched type, or None when none is
available. Several objects can match the same type. The
lookup model explains how owners expose objects
and consumers find them.
Choose a source¶
Every lookup offers the same type-based query interface. The source determines which objects are available and how that availability can change. Fixed membership keeps the same objects in the lookup without freezing the objects themselves.
-
Generic — changing membership
Use
GenericLookupwithInstanceContentwhen the owner needs to add or remove objects as the application runs. -
Fixed / simple — a known collection
Use
fixed(*objects)for objects chosen at construction. With several members, the factory selectsSimpleLookupand preserves their supplied order. -
Singleton — one object
Use
singleton(obj)to expose one existing object through the lookup interface. -
Empty — no objects
Use
fixed()orEmptyLookup()where a lookup is required but nothing is available. -
Proxy — several sources together
Use
ProxyLookupto combine sources, such as document-specific objects and application-wide objects. -
Delegated — one selected source
Use
DelegatedLookupto follow a provider's lookup. After changing the supplied source, calllookup_updated()to refresh the outer lookup. -
Entry point — package contributions
Use
EntryPointLookupto load a named group of installed package contributions. It constructs all contributions immediately and keeps fixed membership.
Explore the documentation¶
- Find your first objects walks through queries, matching parent types and missing objects.
- Observe a changing selection introduces changing membership and result listeners.
- Task guides cover membership, observation, composition, deferred creation and package discovery.
- Public API describes the supported interfaces and their limits.
- Lifetime and change notifications explains what to retain while observing a result and when notifications occur.
For the background to the library, see Project origins.
Lookups supports CPython 3.11–3.15 and follows Semantic Versioning. The experimental package is excluded from its compatibility guarantees.