Skip to main content

confidence 😎

Confidence makes it easy to load one or multiple sources of configuration values and exposes them as a simple to use Python object. Given the following YAML file:

foo:
  bar: 42

foo.baz: '21 is only half the answer'

foobar: the answer is ${foo.bar}…

Use it with confidence:

# load configuration from a YAML file
configuration = confidence.loadf('path/to/configuration.yaml')

# a Configuration object is like a read-only dict, but better
value = configuration.get('foo.bar')
value = configuration.get('foo.bar', default=42)
# or even kwargs, should you want to
# (passing bar=42 and baz='21 is only half the answer')
function(**configuration.foo)

# namespaces are one honking great idea -- let's do more of those!
value = configuration.foo.bar
# they're even safe when values might be missing
value = configuration.foo.whoopsie
if value is NotConfigured:
    value = 42
# or, similar
value = configuration.foo.whoopsie or 42

# even references to other configured values will work
value = configuration.foobar  # 'the answer is 42…'

Often, combining multiple sources of configuration can be useful when defining defaults or reading from multiple files:

configuration = confidence.loadf('/etc/system-wide-defaults.yaml',
                                 './local-overrides.yaml')

# confidence provides a convenient way of using this kind of precedence,
# letting 'more local' files take precedence over system-wide sources
# load_name will attempt to load multiple files, skipping ones that
# don't exist (using typical *nix paths, XDG-specified locations, some
# Windows environment variables and typical OSX paths):
# - /etc/xdg/app.yaml
# - /etc/app.yaml
# - /Library/Preferences/app.yaml
# - C:/ProgramData/app.yaml
# - ~/.config/app.yaml
# - ~/Library/Preferences/app.yaml
# - ~/AppData/Roaming/app.yaml
# - ~/.app.yaml
# - ./app.yaml

configuration = confidence.load_name('app')

# if set, load_name will take a look at environment variables like
# APP_FOO_BAR and APP_FOO_BAZ, mixing those in as foo.bar and foo.baz

# the default load order can be overridden if necessary:

configuration = confidence.load_name('app', load_order=confidence.loaders(
    # loading system after user makes system locations take precedence
    confidence.Locality.USER, confidence.Locality.SYSTEM
))

# prefer using .yml file names instead? tweak the format:

configuration = confidence.load_name('app', format=YAML('.yml'))

# it doesn't even need to be YAML, TOML is included:

configuration = confidence.load('app', format=TOML('.conf'))

While powerful, no set of convenience functions will ever satisfy everyone's use case. To be able to serve as wide an audience as possible, confidence doesn't hide away its flexible internal API.

# let's say application defaults are available as a dict in source
app_defaults = {'foo': {'bar': 42},
                'foo.baz': '21 is only half the answer'}

# and we've already created a way to read a dict from somewhere
def read_from_source(name):
    ...
    return read_values

# all of this can be combined to turn it into a single glorious Configuration instance
# precedence rules apply here, values from read_from_source will overwrite both
# app_defaults and values read from files (the latter of which will use some 
# user-supplied Format to read the file)
configuration = confidence.Configuration(
    app_defaults,
    # yeah, these would be a Configuration instances
    # remember it's just like a dict?
    confidence.loadf('path/to/app.yaml'),
    confidence.loadf('another/file/somewhere.ini', format=MyINIFormat),
    read_from_source('app'),
)

# make it so, no. 1
run_app(configuration)

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

confidence-0.18-py3-none-any.whl (21.3 kB view details)

Uploaded Python 3

File details

Details for the file confidence-0.18-py3-none-any.whl.

File metadata

  • Download URL: confidence-0.18-py3-none-any.whl
  • Upload date:
  • Size: 21.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for confidence-0.18-py3-none-any.whl
Algorithm Hash digest
SHA256 b475838497d430edd1bf1bed99b63affa4a7a5f86e5eaf23f894bcaa52d10d1d
MD5 0f1d94e0e266ad9e18b517a85e4ac362
BLAKE2b-256 08e909deacab5f728b630ddb8440292712459ce0307315ce4161c1cf1435c09b

See more details on using hashes here.

Provenance

The following attestation bundles were made for confidence-0.18-py3-none-any.whl:

Publisher: release.yml on NetherlandsForensicInstitute/confidence

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

0.18 This release

1 file

0.17.2

1 file

0.17.1

1 file

0.17

1 file

0.16.1

1 file

0.16

1 file

0.15

1 file

0.14

1 file

0.13

1 file

0.12

1 file

0.11

1 file

0.10

1 file

0.9

1 file

0.8

1 file

0.7

1 file

0.6.3

1 file

0.6.2

1 file

0.6.1

1 file

0.6

1 file

0.5

1 file

0.4.1

1 file

0.4

1 file

0.3

1 file

0.2

1 file

0.1.1

1 file

0.1

1 file

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page