databroker.Broker.dynamic_alias

Broker.dynamic_alias(key, func)[source]

Create an alias for a “dynamic” query, a function that returns a query.

Parameters
keystring

must be a valid Python identifier

funccallable

When called with no arguments, must return a dict that is a valid query.

Examples

Define an alias to get headers from the last 24 hours.

>>> import time
>>> db.dynamic_alias('today',
...                  lambda: {'since': time.time() - 24*60*60})

Use it.

>>> headers = db.today

Define an alias to get headers with the ‘user’ field in metadata matches the current logged-in user.

>>> import getpass
>>> db.dynamic_alias('mine', lambda: {'user': getpass.getuser()})

Use it

>>> headers = db.mine