Skip to main content

Simple, flexible, and secure settings management for Python.

Project description

Codecov https://www.bestpractices.dev/projects/10423/badge?cache_seconds=0

Three ways to use your settings, guaranteed to work the way you’ve always just wanted!

  • Simply set and get in sfs-settings itself

  • Simply set and get in the calling module

  • Simply use it for your own settings pattern

Full documentation is available here.

Requirements

  • Python 3.11+

  • Poetry 1.9+

  • Pydantic 2.0+

  • keyring = “^25.0.0”

  • dotenv = “^0.9.0”

How to use

Set and get in sfs-settings itself

import sfs_settings as sfs

sfs.track_env_var("URL", str)
sfs.track_secret_var("API_KEY", str)

print(sfs.URL)
print(sfs.API_KEY)

Do use this if:

  • You’re an end application only and don’t need to combine settings obtained from multiple sources.

Don’t use this if:

  • You’re a re-usable module.

  • Need to combine settings obtained from multiple sources.

Set and get in the calling module

from sfs_settings import set_env_var_locally, set_secret_var_locally

set_env_var_locally("URL", str)
set_secret_var_locally("API_KEY", str)

print(URL)
print(API_KEY)

Do use this if:

  • You’re an end application only and don’t need to combine settings obtained from multiple sources.

  • You’re a re-usable module.

Don’t use this if:

  • Need to combine settings obtained from multiple sources.

Use it for your own settings pattern

from sfs_settings import return_env_var, return_secret_var

URL: str = return_env_var("URL", str)
API_KEY: str = return_secret_var("API_KEY", str)

print(URL)
print(API_KEY)

Do use this if:

  • You’re an end application only and don’t need to combine settings obtained from multiple sources.

  • You’re a re-usable module.

  • Need to combine settings obtained from multiple sources.

Don’t use this if:

  • You can use a simpler pattern above.

.env support

sfs-settings supports .env files! It automatically loads them from the current working directory. If you need to have easy swapping between development, local, testing, cloud, and other configurations then swapping .env files is a great way to do it.

per-user application settings

sfs-settings does not yet support keeping settings somewhere in ~/.config/… We’re working on it.

debugging support?

It’s kinda complicated inside sfs-settings actually. So when if you’re using a more complicated setup and things seem a little too magical? It isn’t implemented yet, but it is on the roadmap to add a DEBUG mode.

No downtime to atomically change settings? Transaction locks incoming!

While not here yet, sfs-settings will support transaction locks so that you don’t need to stop your container or VM in order to guarantee correct settings at all times. So, how do you feel about sub-millisecond not even downtime, but pauses? We think that they’re just swell!

When it lands, you’ll be able to do something like this:

export sfs_settings_TRANSACTION_LOCK="*"
export MY_SETTING_ONE="Hello"
export MY_SETTING_TWO="World"
unset sfs_settings_TRANSACTION_LOCK

Just remember that these will ONLY work for settings which have reobtain_each_usage=True!

Looking for something with more nuance than ‘halt everything’? We’ve got you covered! See the specific for transactional locks documentation for more details.

Integrations

sfs-settings does its best to promote 12-factor app principles. This means that it does its best to integrate with other modules which do the same. Here are some of the integrations it supports:

keyring backends

keyring, the python module for integrating with system password managers like Windows Credential Manager, macOS Keychain, and GNOME Keyring, is supported by this module. However, not all backends are supported out of the box, particularly for cloud deployments. If you need support for additional backends, more can be found at the keyring pypi page <https://pypi.org/project/keyring/>. For examples on how to use these additional backends, please review the backend configuration guide.

.env support

sfs-settings supports .env files! It automatically loads them from the current working directory. If you need to have easy swapping between development, local, testing, cloud, and other configurations then swapping .env files is a great way to do it. Examples of how to use .env files can be found in the environment variables guide.

Build

poetry build

Test

poetry run nox

Build Documentation

poetry run sphinx-build -b html docs/source docs/build/html

License

MIT <LICENSE>

Contributing, bug reports, and support

The jist is that you should use the github issue tracker to report bugs and feature requests. If you’re interested in contributing, please see the CONTRIBUTING.rst file for more information.

All PRs must be signed and maintain 100% test coverage.

Please see the Code of Conduct <CODE_OF_CONDUCT.rst> and the Contributing requirements <CONTRIBUTING.rst> for more information.

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

sfs_settings-0.9.1.tar.gz (9.8 kB view details)

Uploaded Source

Built Distribution

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

sfs_settings-0.9.1-py3-none-any.whl (9.7 kB view details)

Uploaded Python 3

File details

Details for the file sfs_settings-0.9.1.tar.gz.

File metadata

  • Download URL: sfs_settings-0.9.1.tar.gz
  • Upload date:
  • Size: 9.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for sfs_settings-0.9.1.tar.gz
Algorithm Hash digest
SHA256 1f2560ba15dd350bc545aaf4c44cd4fb1408501d9a9ece952518767934a6f6cb
MD5 48299e2ab9d835110fc5f25f976f602c
BLAKE2b-256 b5cb07ba6530bfef24ad1d75e75a63a77c9d432919fd179ad5d979fd642cc34d

See more details on using hashes here.

Provenance

The following attestation bundles were made for sfs_settings-0.9.1.tar.gz:

Publisher: pypi_publish.yml on anadon/sfs-settings

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

File details

Details for the file sfs_settings-0.9.1-py3-none-any.whl.

File metadata

  • Download URL: sfs_settings-0.9.1-py3-none-any.whl
  • Upload date:
  • Size: 9.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for sfs_settings-0.9.1-py3-none-any.whl
Algorithm Hash digest
SHA256 fdf0eee5eb1b6a23b8fe2dfa3bd7a85f9a3131e7efcd41bb5c3a6f1c2f4a2439
MD5 2e45f7a7f5edce703462d80ed48dd9a7
BLAKE2b-256 bb75be69594cd30154f9189aeca31655f4e412019584b354c1e8f66898c6715d

See more details on using hashes here.

Provenance

The following attestation bundles were made for sfs_settings-0.9.1-py3-none-any.whl:

Publisher: pypi_publish.yml on anadon/sfs-settings

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

Supported by

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