runtime-config-py


Nameruntime-config-py JSON
Version 0.0.8 PyPI version JSON
download
home_pagehttps://github.com/runtime-config/runtime-config-py
SummaryLibrary for runtime updating project settings.
upload_time2022-12-15 20:48:21
maintainerAleksey Petrunnik
docs_urlNone
authorAleksey Petrunnik
requires_python>=3.8,<3.12
licenseMIT
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            ![license](https://img.shields.io/pypi/l/runtime-config-py?style=for-the-badge) ![python version](https://img.shields.io/pypi/pyversions/runtime-config-py?style=for-the-badge) [![version](https://img.shields.io/pypi/v/runtime-config-py?style=for-the-badge)](https://pypi.org/project/runtime-config-py/) [![coverage](https://img.shields.io/codecov/c/github/runtime-config/runtime-config-py/master?style=for-the-badge)](https://app.codecov.io/gh/runtime-config/runtime-config-py) [![tests status](https://img.shields.io/github/workflow/status/runtime-config/runtime-config-py/Tests/master?style=for-the-badge)](https://github.com/runtime-config/runtime-config-py/actions?query=branch%3Amaster) [![](https://img.shields.io/pypi/dm/runtime-config-py?style=for-the-badge)](https://pypi.org/project/runtime-config-py/)

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](https://github.com/runtime-config/runtime-config), 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](#installation)
- [Usage](#usage)
- [Backend](#backend)
- [Development](#development)
  - [Tests](#tests)
  - [Style code](#style-code)


# 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](./example).

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

```python
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](https://github.com/runtime-config/runtime-config) 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:

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

# Backend

Currently, only 1 [backend](https://github.com/runtime-config/runtime-config) 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.

```python
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
```

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/runtime-config/runtime-config-py",
    "name": "runtime-config-py",
    "maintainer": "Aleksey Petrunnik",
    "docs_url": null,
    "requires_python": ">=3.8,<3.12",
    "maintainer_email": "petrunnik.a@gmail.com",
    "keywords": "",
    "author": "Aleksey Petrunnik",
    "author_email": "petrunnik.a@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/c0/c0/78b22b2485067020679b54c7b25bace476d6f5870d97e6f9071347fdd17b/runtime_config_py-0.0.8.tar.gz",
    "platform": null,
    "description": "![license](https://img.shields.io/pypi/l/runtime-config-py?style=for-the-badge) ![python version](https://img.shields.io/pypi/pyversions/runtime-config-py?style=for-the-badge) [![version](https://img.shields.io/pypi/v/runtime-config-py?style=for-the-badge)](https://pypi.org/project/runtime-config-py/) [![coverage](https://img.shields.io/codecov/c/github/runtime-config/runtime-config-py/master?style=for-the-badge)](https://app.codecov.io/gh/runtime-config/runtime-config-py) [![tests status](https://img.shields.io/github/workflow/status/runtime-config/runtime-config-py/Tests/master?style=for-the-badge)](https://github.com/runtime-config/runtime-config-py/actions?query=branch%3Amaster) [![](https://img.shields.io/pypi/dm/runtime-config-py?style=for-the-badge)](https://pypi.org/project/runtime-config-py/)\n\nruntime-config-py\n=================\n\nThis library allows you to update project settings at runtime. In its basic use case, it is just a client for the\n[server](https://github.com/runtime-config/runtime-config), but if necessary, you can implement your adapter for the\ndesired source and get settings from them.\n\nruntime-config-py supports Python 3.8+.\n\nExamples of using:\n\n- Create feature flags to control which features are enabled for users. Feature flags are especially useful when the\nservice is based on a microservice architecture and the addition of a new feature affects multiple services.\n\n- Quick response to problems in project infrastructure. For example, if one of consumers sends too many requests to\nanother service, and you need to reduce its performance.\n\n\nTable of contents:\n\n- [Installation](#installation)\n- [Usage](#usage)\n- [Backend](#backend)\n- [Development](#development)\n  - [Tests](#tests)\n  - [Style code](#style-code)\n\n\n# Installation\n\nYou can install the library like this:\n\n- from pypi\n\n  ```\n  pip install \"runtime-config-py[aiohttp]\"\n  ```\n\n  or\n\n  ```\n  poetry add runtime-config-py -E aiohttp\n  ```\n\n- from git:\n\n  ```\n  pip install git+https://github.com/runtime-config/runtime-config-py.git#egg=\"runtime-config-py[aiohttp]\"\n  ```\n\n\nSource dependencies have been moved to extras to give you more control over which libraries are installed. If you\nhave a project dependency on a certain version of aiohttp you can install the library without specifying extras.\n\n```\npip install runtime-config-py\n```\n\n# Usage\n\nExamples of using the library can be found [here](./example).\n\nLet's see a simple example of using this library together with aiohttp application.\n\n```python\nfrom aiohttp import web\n\nfrom runtime_config import RuntimeConfig\nfrom runtime_config.sources import ConfigServerSrc\n\n\nasync def hello(request):\n    name = request.app['config'].name\n    return web.Response(text=f'Hello world {name}!')\n\n\nasync def init(application):\n    source = ConfigServerSrc(host='http://127.0.0.1:8080', service_name='hello_world')\n    config = await RuntimeConfig.create(init_settings={'name': 'Alex'}, source=source)\n    application['config'] = config\n\n\nasync def shutdown(application):\n    await application['config'].close()\n\n\napp = web.Application()\napp.on_startup.append(init)\napp.on_shutdown.append(shutdown)\napp.add_routes([web.get('/', hello)])\nweb.run_app(app, port=5000)\n```\n\nBefore running this code, you need to run [server](https://github.com/runtime-config/runtime-config) from which this\nlibrary can take new values for your variables.\nIf you don't do this, nothing bad will not happen. You simply cannot change the value of the name variable at runtime :)\n\n**Automatic source initialization**\n\nYou can simplify library initialization by automatically creating a source instance. Simply define the following\nenvironment variables and the source instance will be created automatically:\n\n- RUNTIME_CONFIG_HOST\n- RUNTIME_CONFIG_SERVICE_NAME\n\n**Ways to access settings**\n\nThis library supports several ways to access variables. All of them are shown below:\n\n```python\nprint(config.name)\nprint(config['name'])\nprint(config.get('name', default='Dima'))\n```\n\n# Backend\n\nCurrently, only 1 [backend](https://github.com/runtime-config/runtime-config) is supported. Later, support for other\nbackends, such as redis, will probably be added to the library, but this is not in the nearest plans.\n\nIf you need support for another settings storage source right now, you can write your own source. Implementing this is\nvery simple. You need to create a class that will be able to retrieve data from the desired source and will inherit\nfrom `runtime_config.sources.base.BaseSource`. After that, an instance of the class you created must be passed to\nthe `RuntimeConfig.create` method.\n\n```python\nyour_source = YourSource(...)\nconfig = await RuntimeConfig.create(..., source=your_source)\n```\n\n\n# Development\n\n## Install deps\n\n```\npoetry install --all-extras\n```\n\n## Tests\n\nCheck the work of the library on several versions of Python at once using the command below:\n\n```\nmake test-multi-versions\n```\n\nThe simple test run is available through the command below:\n\n```\nmake test\n```\n\n\n## Style code\n\nFor automatic code formatting and code verification, you need to use the command below:\n\n```\nmake lint\n```\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Library for runtime updating project settings.",
    "version": "0.0.8",
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "md5": "66f72048b3dae755ef004b79b2b2a3ff",
                "sha256": "8b9b0959d1d8fe51f8b34b98e23318337c4d935b6116c7318e425cd127f79f99"
            },
            "downloads": -1,
            "filename": "runtime_config_py-0.0.8-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "66f72048b3dae755ef004b79b2b2a3ff",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8,<3.12",
            "size": 10486,
            "upload_time": "2022-12-15T20:48:19",
            "upload_time_iso_8601": "2022-12-15T20:48:19.424901Z",
            "url": "https://files.pythonhosted.org/packages/fc/9b/ad3d58990205a0d34decd8f27f6480d86decf53711471599a09770b8fb0e/runtime_config_py-0.0.8-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "md5": "35f0bae616e2cae1a162f974b88a1545",
                "sha256": "b79cce65c8d4e4158b16ab2d7d7cc60e30709e7808dd98fe5d8745489da18412"
            },
            "downloads": -1,
            "filename": "runtime_config_py-0.0.8.tar.gz",
            "has_sig": false,
            "md5_digest": "35f0bae616e2cae1a162f974b88a1545",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8,<3.12",
            "size": 10243,
            "upload_time": "2022-12-15T20:48:21",
            "upload_time_iso_8601": "2022-12-15T20:48:21.389077Z",
            "url": "https://files.pythonhosted.org/packages/c0/c0/78b22b2485067020679b54c7b25bace476d6f5870d97e6f9071347fdd17b/runtime_config_py-0.0.8.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2022-12-15 20:48:21",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "runtime-config",
    "github_project": "runtime-config-py",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "runtime-config-py"
}
        
Elapsed time: 0.01987s