Package: config-client-pcf-c3
config-clientconfig-client package forspring cloud config.InstallingInstall and update using pip:pipinstall-Uconfig-clientDependenciesattrsglomrequestsSetupThe default URL pattern is:CONFIGSERVER_ADDRESS/BRANCH/APP_NAME-PROFILE.json# expected environment variables:#CONFIGSERVER_ADDRESS=http://localhost:8888BRANCH=masterPROFILE=developmentAPP_NAME=myappwill result in:http://localhost:8888/master/myapp-development.jsonThe url pattern can be customize on constructor with parameterurl.fromconfigimportspringc=spring.ConfigClient(app_name='myapp',url="{address}/{branch}/{profile}-{app_name}.json")c.url# output: 'http://localhost:8888/master/development-myapp.json'Default valuesif no value was adjusted for the environment variables below, the default value will be assumed, as:CONFIGSERVER_ADDRESS=http://localhost:8888BRANCH=masterPROFILE=developmentAPP_NAME=Supported response formatJSONJust add the.jsonextension to the end of the URL parameter. For example:c=ConfigClient(app_name='foo',profile='development',address='http://localhost:8000',branch='master',url='{address}/{branch}/{app_name}-{profile}.json'# <)It will result in URL:http://localhost:8000/master/foo-development.json.Notice.yamlit's not supported, all extensions will be converted to.jsoninternally.Usage Exampleusing standard clientfromconfig.springimportConfigClientconfig_client=ConfigClient(app_name='my_app')config_client.get_config()# option 1: dict like with direct accessconfig_client.config['spring']['cloud']['consul']['host']# option 2: dict like using getconfig_client.config.get('spring').get('cloud').get('consul').get('port')# option 3: using get_attribute methodconfig_client.get_attribute('spring.cloud.consul.port')standard client with @decoratorFor use cases where environment variables are set.fromconfigimportspring@spring.config_client()defmy_test(config_client=None):config_client.config['spring']['cloud']['consul']['host']config_client.config.get('spring').get('cloud').get('consul').get('port')config_client.get_attribute('spring.cloud.consul.port')For use cases where environment variables are not set can you use decorator parameters, as example below:fromconfigimportspring@spring.config_client(app_name='myapp',branch="dev")defmy_test(config_client=None):config_client.config['spring']['cloud']['consul']['host']config_client.config.get('spring').get('cloud').get('consul').get('port')config_client.get_attribute('spring.cloud.consul.port')Integration with Flask.fromconfig.springimportConfigClientfromflaskimportFlaskconfig_client=ConfigClient(app_name="myapp")config_client.get_config()app=Flask(__name__)app.run(host='0.0.0.0',port=config_client.config.get('app').get('port')using asyncioclient using asyncioimportasynciofromconfig.springimportConfigClientloop=asyncio.get_event_loop()config_client=ConfigClient(app_name='myapp')config_client.get_config()asyncdefservice_discovery():awaitdiscovery_client.register(config_client.config['app']['name'],config_client.config.get('app').get('port'))discovery_client=Consul(config_client.config.get('spring').get('cloud').get('consul').get('host'),config_client.get_attribute('spring.cloud.consul.port'],loop)loop.run_until_complete(service_discovery)create singleton instanceAssuming default values.fromconfig.springimportcreate_config_clientc=create_config_client()d=create_config_client()print(id(c))print(id(d))With custom values.fromconfig.springimportcreate_config_clientc=create_config_client(address='http://localhost:8888/configuration',app_name='autosprocessuais-pecas-txtos',branch="ft-sdintegracoes-591")d=create_config_client(address='http://localhost:8888/configuration',app_name='autosprocessuais-pecas-txtos',branch="ft-sdintegracoes-591")print(id(c))print(id(d))cloudfoundryintegrationDefault usagefromconfig.cfimportCFcf=CF()cf.get_config()It's necessary bind Config Server with the application first.A example application it's available on:https://github.com/amenezes/simplewebCustom usagefromconfig.cfimportCFfromconfig.springimportConfigClientcf=CF(client=ConfigClient(app_name='simpleweb000',url="{address}/{branch}/{app_name}.json"))cf.get_config()DevelopmentRunning TestsInstall development dependencies.pipinstall-rrequirements-dev.txtTo execute tests just run:python-mpytest-v--cov-reportterm--cov=configtestsLinksLicense:Apache LicenseCode:https://github.com/amenezes/config-clientIssue tracker:https://github.com/amenezes/config-client/issues