Skip to main content
***************
runtime-context
***************

.. code-block:: shell

pip install runtime-context


--------------------------
``RuntimeContextWrapper`` Example
--------------------------

.. code-block:: python

from runtime_context import RuntimeContextWrapper

runtime_context = RuntimeContextWrapper()


def do_something(i):
if runtime_context.dry_run:
print('{} - dry run'.format(i))
else:
print('{} - for real'.format(i))


with runtime_context(dry_run=False):
do_something(1) # for real

with runtime_context(dry_run=True):
do_something(2) # dry run

runtime_context.dry_run = False
do_something(3) # for real

with runtime_context():
do_something(4) # for real

runtime_context.dry_run = True
do_something(5) # dry run

do_something(6) # for real


-------------------------------
``runtime_context_env`` Example
-------------------------------

.. code-block:: python

import json
from typing import Union # noqa

from runtime_context import EnvBase, runtime_context_env # noqa


@runtime_context_env
class YourApp:
dry_run = False
db_name = None
config_file = None


env = YourApp() # type: Union[YourApp, EnvBase]


@env.context_var_set.listener(predicate=lambda name: name == 'config_file')
def reload_config():
if not env.config_file:
return

print('Reloading config from {}'.format(env.config_file))
with open(env.config_file) as f:
config = json.load(f)
for k, v in config.items():
env.set(k, v)


with env():
assert env.dry_run is False
assert env.db_name is None

env.config_file = 'config.json' # prints 'Reloading config from config.json'

assert env.db_name == 'products' # read from config.json file

with env(dry_run=True):
assert env.dry_run is True

Metadata

Release files for runtime-context 3.0.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 runtime-context 3.0.0
File Size Uploaded
runtime-context-3.0.0.tar.gz 7.9 kB Details

Release files / runtime-context-3.0.0.tar.gz

Download URL runtime-context-3.0.0.tar.gz
Size 7.9 kB
Tags Source
SHA-256 checksum
How to use checksums
67b874abc357a648776549a0c8fa64e2161467d93cec289d6cd3c2faf7889a06
BLAKE2b-256 checksum
How to use checksums
71935ef03c181cb0f908c14c5cc15e0435464b5f1e592d4ce6a8104e9255ac88
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

3.0.0 This release

1 release file

2.0.0

1 release file

1.3.0

1 release file

1.2.2

1 release file

1.2.1

1 release file

1.2.0

1 release file

1.1.0

1 release file

1.0.0

1 release file

0.5.0

1 release file

0.4.1

1 release file

0.4.0

1 release file

0.3.0

1 release file

0.2.2

1 release file

0.2.1

1 release file

0.2.0

1 release file

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