Skip to main content

Library for runtime updating project settings.

Project description

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

This project can be installed using pip:

pip install runtime-config-py

Or it can be installed directly from git:

pip install git+https://github.com/aleksey925/runtime-config-py.git

Usage

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

from aiohttp import web

from runtime_config import RuntimeConfig
from runtime_config.sources import RuntimeConfigServer


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


async def init(application):
    source = RuntimeConfigServer(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 :)

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.runtime_config_server.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

Tests

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

make test

Style code

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

make lint

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

runtime-config-py-0.0.1.tar.gz (9.1 kB view details)

Uploaded Source

Built Distribution

runtime_config_py-0.0.1-py3-none-any.whl (9.5 kB view details)

Uploaded Python 3

File details

Details for the file runtime-config-py-0.0.1.tar.gz.

File metadata

  • Download URL: runtime-config-py-0.0.1.tar.gz
  • Upload date:
  • Size: 9.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.13 CPython/3.8.13 Darwin/21.6.0

File hashes

Hashes for runtime-config-py-0.0.1.tar.gz
Algorithm Hash digest
SHA256 d70997f6eac2f7ac4615f058bfa2e152c62b477c1ce50770e784d493b359b3c8
MD5 06e6acd89d4717f50eaa84ee46b7fa2b
BLAKE2b-256 ca6f77d78e3df87356453db671ca7ff3698f496b6f9197fd498c7f58dbe29ea7

See more details on using hashes here.

File details

Details for the file runtime_config_py-0.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for runtime_config_py-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 da73b716e8a97ea11428ff5df546387606dcd4fb2191b9947b9e30714c2b645a
MD5 2aeaaa0a864606a418e9a3bc14280a67
BLAKE2b-256 d0a19b23d8b9b713fcba8136b3b8fcf95b29ecfa08be6e8c4825295d9fbc1e05

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page