Skip to main content

Auto-discovery of configurations for easy inline use

Project description

[![Build Status](https://travis-ci.org/internap/python-config-probe.svg?branch=master)](https://travis-ci.org/internap/python-config-probe)
[![PyPI version](https://badge.fury.io/py/config-probe.svg)](http://badge.fury.io/py/config-probe)


Mission
=======

Provide an auto-discovery process of configurations for simple code use. Given a path and a list of pattern,
the result config will be a shortcut to any config.

## Usage

Setup:

config = probe(
path="path/to/my/files",
patterns=["path/(*)/file.yaml"]
)

Use it:

print config.mynamespace.key

## Parameters

- **path**

Initial path to probe. Patterns will be tested against the file structure underneath the path
and it will be ignored in determining the namespacing.

- **patterns**

A list of file paths containing (or not) placeholders "(\*)" o find where the configuration files are located.
The patterns definition order defines which keys has the priority, the last one being the most relevant.

Each placeholder in the path will result in a namespace in the resulting config. So let's say you have a pattern

dir1/(*)/dir2/(*).yaml

If this pattern finds the file : "dir1/**ns1**/dir2/**file**.yaml" that contains "key: 'value'", the resulting
config will be

config.ns1.file.key == "value"

now if the pattern was

dir1/ns1/dir2/file.yaml

for the same file, the resulting config would simply be

config.key == "value"

so you can use placeholders "(\*)" to namespace the resulting config and use "\*" without the parenthesis
to have a variable path without the namespacing

dir1/(*)/dir2/*.yaml
config.ns1.key == "value"

## Mocking the probing

Your unit test can have your code use fake_probe instead to which to give a dict and it will appear as if it
was just probed. Example:

config = fake_probe({
"ns1": {
"file": {
"key": "value"
}
}
})
# then
config.ns1.file.key == "value"

Contributing
============

Feel free to raise issues and send some pull request, we'll be happy to look at them!

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

config-probe-0.1.2.tar.gz (10.2 kB view details)

Uploaded Source

File details

Details for the file config-probe-0.1.2.tar.gz.

File metadata

File hashes

Hashes for config-probe-0.1.2.tar.gz
Algorithm Hash digest
SHA256 f38605f0ef4113b2c7cc9bf62bceab8a6b808508e77578ed3623ad4f5ca425d2
MD5 78090a94592c80faf2c91668099e3dd8
BLAKE2b-256 4eb77e7d20444f3bec41bd19383b856b86d9919a1b41c6cba55d6111fb9ac9ae

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