Skip to main content

figtion

            .---.
    .-.     |~~~|
    |~|     |~~~|--.
.---!-|  .--| C |--|
|===|*|--|%%| f |  |
|   |*|__|  | g |  |
|===|*|==|  |   |  |
|   |_|__|  |~~~|__|
|===|~|--|%%|~~~|--|
`---^-^--^--^---`--' hjw

A simple configuration interface with plaintext and encrypted file support.

Benefits

  • seemless Python dict interface
    • unified config definition and defaults
  • YAML text file source for file-system input & serialization
    • nested entries supported
    • optional live reloading
  • simple precedence
    • defaults keys define config keys
    • YAML values override defaults values
  • secrets support
    • secrets saved to private YAML file
    • secrets encrypted at rest via environment variable
    • update & mask from public YAML file

Examples

Config Definition and Defaults

import figtion

defaults = {'my server'       : 'www.bestsite.web'
           ,'number of nodes' : 5
           ,'password'        : 'huduyutakeme4'
           ,'nested stuff'    : {'breakfast' : 'coffee'}
           ,'listed stuff'    : ['a','b','c']}

cfg = figtion.Config(defaults=defaults,filepath='./conf.yml')

print(cfg['my server'])  

This will print either 'www.bestsite.web' or the value of 'my server' in ./conf.yml if it is something else.

defaults strictly defines the schema. Only keys present in defaults from a serial file will be retained. If you want to risk unspecified input keys and load everything from the YAML file, you can either omit the defaults parameter or set promiscuous=True when constructing Config.

Self-Documenting Plaintext

Specify if/when you want to update stored plaintext file.

cfg = figtion.Config(..., promiscuous=True)
...
cfg.dump()

If concise=True, only modified values are stored in text file. If promiscuous=False (default behavior), deprecated values are quietly removed. Otherwise, serialized YAML will clarify default, modified, and deprecated values:

##############################
####       Modified       ####
##############################
my server: www.newsite.web


##############################
####       Default        ####
##############################
number of nodes: 5


##############################
####      Deprecated      ####
##############################
fave cat: Zelda

Dynamic Reloading

cfg = figtion.Config(defaults=defaults, filepath='./conf.yml', reload_interval=5)

# ...some time later, after ./conf.yml has been edited externally...
value = cfg['my server']   # triggers an mtime check; reloads if changed

if cfg.changed:
    # propagate the new values to your application, then clear the flag
    restart_workers()
    cfg.changed = False

reload_interval is in seconds and defaults to 5. Pass 0 to check on every read, or None to disable dynamic reloading entirely. The changed flag is only set when an actual value differs after reload. Touching the file without changing content will not flip it.

Config Secrets

When you want a public config file and a separate secret one. To keep secret encrypted "at rest", set a secret key environment variable FIGKEY.

os.environ["FIGKEY"] = "seepost-itnote"

cfg = figtion.Config(defaults=defaults,filepath='./conf.yml',secretpath='./creds.yml')
cfg.mask('password')

print(cfg['password'])

This will print the value of 'password', which is stored in ./creds.yml and not ./conf.yml. If the value of 'password' is changed in either YAML file, the password will be updated in ./creds.yml and masked from ./conf.yml the next time the class is loaded in Python. If a secret key is present via environment variable FIGKEY, the values in ./creds.yml will be encrypted using that key. The dictionary object returned for cfg contains the true value.

If you want everything treated as secret, provide a secretpath and omit filepath:

cfg = figtion.Config(secretpath='./creds.yml')

In this case, no call to mask is needed and everything is encrypted at rest.

Encryption Details

This uses the pynacl bindings to the libsodium library, which uses the XSalsa20 algorithm for encryption. The encryption key provided by the FIGKEY environment variable is truncated to a 32-byte string.

Metadata

Release files for figtion 1.3.2

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

Source distribution (sdist)

Source distribution for figtion 1.3.2
File Size Uploaded Provenance Actions
figtion-1.3.2.tar.gz 18.1 kB Without provenance Details for figtion-1.3.2.tar.gz

Built distribution (wheel)

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

Total release size: 30.6 kB

Release files / figtion-1.3.2.tar.gz

Download URL figtion-1.3.2.tar.gz
Size 18.1 kB
Tags Source
SHA-256 checksum
How to use checksums
b23f57b4b6d8bddec3ffa2ef91557954f7a25f2b493233e9070c384c3b77df76
BLAKE2b-256 checksum
How to use checksums
9153bff6ea932c3de38a7bffae9bf513ec6562b5102e1366e2b57898fe210de2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.4

Release files / figtion-1.3.2-py3-none-any.whl

Download URL figtion-1.3.2-py3-none-any.whl
Size 12.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
73ad1824bd9054ed0612cca652a26c1a4b06004f9f8ac98789f8979bebbd8a17
BLAKE2b-256 checksum
How to use checksums
0fb8b08869e5739ec09a802bfb05127b3588748f14e93a7963c25f35339e0963
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.4

Security for figtion 1.3.2

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