config service client
Project description
config-client
config-client package for spring cloud config.
Installing
Install and update using pip:
pip install -U config-client
Dependencies
Setup
The default URL pattern is:
CONFIGSERVER_ADDRESS
/BRANCH
/APP_NAME
-PROFILE
.json
# expected environment variables: # CONFIGSERVER_ADDRESS=http://configserver:8888/configuration BRANCH=master PROFILE=development APP_NAME=myapp
will result in:
http://configserver:8888/configuration/master/myapp-development.json
the url pattern can be customize on constructor with parameter
url
.
from config import spring c = spring.ConfigServer( app_name='myapp', url="{address}/{branch}/{profile}-{app_name}.json" ) c.url # output: 'http://localhost:8888/configuration/master/development-myapp.json'
Default values
if no value was adjusted for the environment variables below, the default value will be assumed, as:
CONFIGSERVER_ADDRESS=http://localhost:8888/configuration BRANCH=master PROFILE=development APP_NAME=
Usage Example
using standard client
from config.spring import ConfigServer config_client = ConfigServer(app_name='my_app') config_client.get_config() # option 1: dict like config_client.config['spring']['cloud']['consul']['host'] # option 2: dict like using get config_client.config.get('spring').get('cloud').get('consul').get('port') # option 3: using get_attribute method config_client.config.get_attribute('spring.cloud.consul.port')
standard client with @decorator
from config import spring @spring.config_client def my_test(config_client=None): config_client.config['spring']['cloud']['consul']['host'] config_client.config.get('spring').get('cloud').get('consul').get('port') config_client.config.get_attribute('spring.cloud.consul.port')
Integration with Flask.
from config.spring import ConfigServer from flask import Flask config_client = ConfigServer(app_name="myapp") config_client.get_config() app = Flask(__name__) app.run(host='0.0.0.0', port=config_client.config['app']['port']
using asyncio
client using asyncio
import asyncio from config.spring import ConfigServer loop = asyncio.get_event_loop() config_client = ConfigServer(app_name='myapp') config_client.get_config() async def service_discovery(): await discovery_client.register( config_client.config['app']['name'], config_client.config.get('app').get('port') ) discovery_client = Consul( config_client.config['spring']['cloud']['consul']['host'], config_client.config['spring']['cloud']['consul']['port'], loop ) loop.run_until_complete(service_discovery)
Development
Running Tests
Install development dependencies.
pip install -r requirements-dev.txt
To execute tests just run:
python -m pytest -v --cov-report term --cov=config tests
Links
- License: Apache License
- Code: https://github.com/amenezes/config-client
- Issue tracker: https://github.com/amenezes/config-client/issues
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Filename, size | File type | Python version | Upload date | Hashes |
---|---|---|---|---|
Filename, size config_client-0.3.0-py3-none-any.whl (8.5 kB) | File type Wheel | Python version py3 | Upload date | Hashes View |
Filename, size config-client-0.3.0.tar.gz (4.2 kB) | File type Source | Python version None | Upload date | Hashes View |
Close
Hashes for config_client-0.3.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1daef2ccc3a380901f8ccc5aff850f99d5b324337167f8db6e52c6a2105a3a75 |
|
MD5 | 366b4de7794d7e733736f53e4723e703 |
|
BLAKE2-256 | ff91bd0a4baf5a7a15b02b4316075603985c7912a7b4260eb3d6eb88a727511a |