Skip to main content

license python version version coverage tests status

runtime-config-py

This library allows you to update project settings at runtime. In its basic use case, it is just a client for the server, but if necessary, you can implement your adapter for the desired source and get settings from them.

runtime-config-py supports Python 3.8+.

Examples of using:

  • Create feature flags to control which features are enabled for users. Feature flags are especially useful when the service is based on a microservice architecture and the addition of a new feature affects multiple services.

  • Quick response to problems in project infrastructure. For example, if one of consumers sends too many requests to another service, and you need to reduce its performance.

Table of contents:

Installation

You can install the library like this:

  • from pypi

    pip install "runtime-config-py[aiohttp]"
    

    or

    poetry add runtime-config-py -E aiohttp
    
  • from git:

    pip install git+https://github.com/runtime-config/runtime-config-py.git#egg="runtime-config-py[aiohttp]"
    

Source dependencies have been moved to extras to give you more control over which libraries are installed. If you have a project dependency on a certain version of aiohttp you can install the library without specifying extras.

pip install runtime-config-py

Usage

Examples of using the library can be found here.

Let's see a simple example of using this library together with aiohttp application.

from aiohttp import web

from runtime_config import RuntimeConfig
from runtime_config.sources import ConfigServerSrc


async def hello(request):
    name = request.app['config'].name
    return web.Response(text=f'Hello world {name}!')


async def init(application):
    source = ConfigServerSrc(host='http://127.0.0.1:8080', service_name='hello_world')
    config = await RuntimeConfig.create(init_settings={'name': 'Alex'}, source=source)
    application['config'] = config


async def shutdown(application):
    await application['config'].close()


app = web.Application()
app.on_startup.append(init)
app.on_shutdown.append(shutdown)
app.add_routes([web.get('/', hello)])
web.run_app(app, port=5000)

Before running this code, you need to run server from which this library can take new values for your variables. If you don't do this, nothing bad will not happen. You simply cannot change the value of the name variable at runtime :)

Automatic source initialization

You can simplify library initialization by automatically creating a source instance. Simply define the following environment variables and the source instance will be created automatically:

  • RUNTIME_CONFIG_HOST
  • RUNTIME_CONFIG_SERVICE_NAME

Ways to access settings

This library supports several ways to access variables. All of them are shown below:

print(config.name)
print(config['name'])
print(config.get('name', default='Dima'))

Backend

Currently, only 1 backend is supported. Later, support for other backends, such as redis, will probably be added to the library, but this is not in the nearest plans.

If you need support for another settings storage source right now, you can write your own source. Implementing this is very simple. You need to create a class that will be able to retrieve data from the desired source and will inherit from runtime_config.sources.base.BaseSource. After that, an instance of the class you created must be passed to the RuntimeConfig.create method.

your_source = YourSource(...)
config = await RuntimeConfig.create(..., source=your_source)

Development

Install deps

poetry install --all-extras

Tests

Check the work of the library on several versions of Python at once using the command below:

make test-multi-versions

The simple test run is available through the command below:

make test

Style code

For automatic code formatting and code verification, you need to use the command below:

make lint

Metadata

Release files for runtime-config-py 0.0.8

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-config-py 0.0.8
File Size Uploaded
runtime_config_py-0.0.8.tar.gz 10.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for runtime-config-py 0.0.8
File Interpreter ABI Platform
runtime_config_py-0.0.8-py3-none-any.whl Python 3 none any Details

Total release size: 20.7 kB

Release files / runtime_config_py-0.0.8.tar.gz

Download URL runtime_config_py-0.0.8.tar.gz
Size 10.2 kB
Tags Source
SHA-256 checksum
How to use checksums
b79cce65c8d4e4158b16ab2d7d7cc60e30709e7808dd98fe5d8745489da18412
BLAKE2b-256 checksum
How to use checksums
c0c078b22b2485067020679b54c7b25bace476d6f5870d97e6f9071347fdd17b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.2.2 CPython/3.8.15 Linux/5.15.0-1024-azure

Release files / runtime_config_py-0.0.8-py3-none-any.whl

Download URL runtime_config_py-0.0.8-py3-none-any.whl
Size 10.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8b9b0959d1d8fe51f8b34b98e23318337c4d935b6116c7318e425cd127f79f99
BLAKE2b-256 checksum
How to use checksums
fc9bad3d58990205a0d34decd8f27f6480d86decf53711471599a09770b8fb0e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.2.2 CPython/3.8.15 Linux/5.15.0-1024-azure

Release history Release notifications | RSS feed

This release

0.0.8 This release

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

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