Skip to main content

figga

A very simple configuration manager for Python.

CI builds

Usage

figga currently supports three ways of specifying the configuration:

  • standard Python dictionary
  • environment variables with a common prefix
  • one or more INI files

Basic Usage

The default mechanism of instantiating a figga.Configuration instance is passing a simple Python dictionary:

from figga import Configuration

config = Configuration({'foo': 'bar', 'var1': 123, 'VAR2': 'buzz'})

This mechanism can be easily used to store configuration in any file format which can easily be converted to a dict, such as JSON or YAML:

import json
from figga import Configuration

with open('config.json') as json_config:
    config = Configuration(json.load(json_config))

The instantiated object can be used from elsewhere in your code, e.g. if the above instantiation happened in module somewhere.py:

from somewhere import config

print(config.some_value)

Note that all variable names are normalised to lowercase, and access is case insensitive: config.foo, config.FOO or config.Foo all point to the same value.

In addition to direct access, values can be retrieved using the get method:

config.get('some_value')

Note that get also accepts the default argument, the value of which will override the default value specified at instantiation (see below).

Default Values

All constructor methods accept the argument default, which defines the behaviour when a non-existing value is accessed. This argument can handle three different types of default values:

  • any object or scalar value, which will be returned as-is
  • a callable, which will be called passing the accessed variable name as the only argument, returning its result
  • a BaseException subclass, which will be raised instead of returning a value

If no default value is specified, an unknown variable will have the value of None.

From Environment Variables

Another option to initialize the configuration manager is by taking the values of all the environment variables which begin with a common prefix:

import os
from figga import Configuration

os.environ['YOURAPP_VARIABLE'] = 'foo bar'

config = Configuration.from_environ(prefix='YOURAPP_')

print(config.yourapp_variable)

Optionally you can remove the prefix from the final configuration variables:

config = Configuration.from_environ(prefix='YOURAPP_', remove_prefix=True)

print(config.variable)

From INI Files

Alternatively, figga.Configuration can be instantiated using one or more configparser-compatible files:

from figga import Configuration

config = Configuration.from_files('config1.ini', '/vars/config2.ini')

If the file paths are not absolute, they are assumed to be relative to the current working directory. Paths can be either strings or os.PathLike instances.

Metadata

Release files for figga 0.3.0

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

Built distribution (wheel)

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

Release files / figga-0.3.0-py3-none-any.whl

Download URL figga-0.3.0-py3-none-any.whl
Size 4.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
69c9d4a4ca4fc049d84c45fc80c1e2b8181ebba440b373f542887068cc98705d
BLAKE2b-256 checksum
How to use checksums
21078a273b8991db96062a02480fe5e50285e5e6707a2a9bcaec88f45d6ada66
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.4 CPython/3.7.10 Linux/5.8.0-44-generic

Security for figga 0.3.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