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.4.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.4-py3-none-any.whl (9.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: sfs_settings-0.9.4.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.4.tar.gz
Algorithm Hash digest
SHA256 891767a8380075e0ffed433d7d59abee1342a05a101f0b737dd11eb234dd881a
MD5 89df5f6489b340eeef5d97c337b4c27c
BLAKE2b-256 5499be2ee8fe9d87f0061032337756d7492c5478a8cc338a4f51e6db814a9af0

See more details on using hashes here.

Provenance

The following attestation bundles were made for sfs_settings-0.9.4.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.4-py3-none-any.whl.

File metadata

  • Download URL: sfs_settings-0.9.4-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.4-py3-none-any.whl
Algorithm Hash digest
SHA256 29c54f416c99d79b466d4c9fcdc15ed308efa1a64711f2c86e5c8d09c63734ad
MD5 c3edaccfdac2af434ab7fda089b51ed0
BLAKE2b-256 f04fae60a75f07df612ee29ad3b6d52d86a61e888ab61766755c02be67d29cf9

See more details on using hashes here.

Provenance

The following attestation bundles were made for sfs_settings-0.9.4-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