Skip to main content

Overview

This is a module for reading configuration files.

Currently, the module only supports YAML-formatted files.

Features:

  • Retrieve deeply nested values using dot notation, e.g. section1.key1
  • Retrieve values using wildcards, e.g. section1.*.key2
  • Configuration files can be templated (Jinja)

Prerequisites:

  • Python 3.7+

Installation

  • From pypi: pip3 install btconfig
  • From this git repo: pip3 install git+https://github.com/berttejeda/bert.config.git
    Note: To install a specific version of the library from this git repo,
    suffix the git URL in the above command with @{ tag name }, e.g.:
    git+https://github.com/berttejeda/bert.config.git@3.0.0

Usage Examples

Load a configuration file and retrieve specified key value

Given:

  • Config file at /home/myuser/myconfig.yaml
  • with contents:
section1:
  key1: value1
  key2: value2
  key3: value3
from btconfig import Config
# Initialize App Config
config = Config(config_file_uri='~/myconfig.yaml').read()
value = config.get('section1.key1')
print(value)

The above should return value1

Load a configuration file and retrieve a deeply nested value

Given:

  • Config file at /home/myuser/myconfig.yaml
  • with contents:
section1:
  subsection1:
    item1:
      subitem1: value1
    item2: value2
    item3: value3
  subsection2:
    item1: value1
    item2: value2
    item3: value3
  key1: value1
  key2: value2
  key3: value3
section2:
  item1: value1
from btconfig import Config
# Initialize App Config
config = Config(config_file_uri='~/myconfig.yaml').read()
value = config.get('section1.subsection1.item2')
print(value)

The above should return value2

Load a configuration file and retrieve specified key value using wildcard notation

Given:

  • Config file at /home/myuser/myconfig.yaml
  • with contents:
section1:
  subsection1:
    item1:
      subitem1: value1
    item2: value2
    item3: value3
  subsection2:
    item1: value1
    item2: value2
    item3: value3
  key1: value1
  key2: value2
  key3: value3
section2:
  item1: value1
from btconfig import Config
# Initialize App Config
config = Config(config_file_uri='~/myconfig.yaml').read()
value = config.get('section1.*.item1')
print(value)

The above should return [{'subitem1': 'value1'}, 'value1']

Note: When retrieving values via wildcard, the return value is a list object.

Retrieve values via attribute access

The object returned by read() also supports attribute-style access, as with print(config.section1.subsection1.item2), or via the properties attribute, as with print(config.properties.section1.subsection1.item2)

Note: This approach does not support retrieving values via wildcard reference.

Templating

Config files are only rendered as templates ($VAR substitution from the environment, followed by Jinja) when requested, as with config = Config(config_file_uri='~/myconfig.yaml', templatized=True).read()

Tests

Run pytest test.py

TLS verification

Configs fetched over HTTPS are certificate-checked by default. To load from a host with a self-signed certificate, pass verify_tls=False, as with config = Config(config_file_uri='https://myhost/myconfig.yaml', verify_tls=False).read()

Metadata

Release files for btconfig 7.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for btconfig 7.0.0
File Size Uploaded Provenance Actions
btconfig-7.0.0.tar.gz 10.8 kB Without provenance Details for btconfig-7.0.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for btconfig 7.0.0
File Interpreter ABI Platform Actions
btconfig-7.0.0-py3-none-any.whl Python 3 none any Details for btconfig-7.0.0-py3-none-any.whl

Total release size: 20.1 kB

Release files / btconfig-7.0.0.tar.gz

Download URL btconfig-7.0.0.tar.gz
Size 10.8 kB
Tags Source
SHA-256 checksum
How to use checksums
325ff7c9ecd2f9be64973151ca4b28bcc28693cf51a55602eb03cefa78473028
BLAKE2b-256 checksum
How to use checksums
1c21fa40e5703887ac82352aa22cc9629950a6830a0ddff2ffa1d5590a7c5821
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.6

Release files / btconfig-7.0.0-py3-none-any.whl

Download URL btconfig-7.0.0-py3-none-any.whl
Size 9.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9e5c89ca45908f4dd4211794020fe4dc8d42b0548fb81b5620b9bbe581302adf
BLAKE2b-256 checksum
How to use checksums
3622463bd0139c11e4c0e9cf212d3958e8975f76ae9d09fb5580163afb2bd271
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.6

Security for btconfig 7.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page