Skip to main content

Python settings management with namespacing and modular files. Inspired by Django.

Project description

Pyttings

Lightweight Python settings management with namespacing and modular files. Inspired by Django.

Features

  • Namespaced Settings: Use a prefix (e.g., PYTTING_) to avoid conflicts.
  • Custom Prefix: Change the prefix using PYTTING_ENV_PREFIX.
  • Modular Settings: Load settings from a module with PYTTING_SETTINGS_MODULE.
  • Environment Variables: Override settings easily, with automatic type parsing.

Installation

pip install pyttings

Quick Start

  1. Define Your Settings Module (myapp/settings.py):
DEBUG = True
DATABASE_URL = "sqlite:///db.sqlite3"
SECRET_KEY = "my-secret-key"
  1. Set the Settings Module:
export PYTTING_SETTINGS_MODULE="myapp.settings"
  1. Use Pyttings:
from pyttings import settings

print(settings.DEBUG)  # Output: True
print(settings.DATABASE_URL)  # Output: sqlite:///db.sqlite3

Configuration

Required: PYTTING_SETTINGS_MODULE

Specify the settings module using the PYTTING_SETTINGS_MODULE environment variable. This is mandatory for Pyttings to know where to load your settings from.

export PYTTING_SETTINGS_MODULE="myapp.settings"

Optional: PYTTING_ENV_PREFIX

By default, Pyttings uses PYTTING_ as the prefix for environment variables. For example, to override the DEBUG setting, you would set:

export PYTTING_DEBUG="False"

If you want to use a custom prefix (e.g., MYAPP_), set the PYTTING_ENV_PREFIX environment variable:

export PYTTING_ENV_PREFIX="MYAPP_"
export MYAPP_DEBUG="False"

Now, Pyttings will look for MYAPP_DEBUG instead of PYTTING_DEBUG.

Automatic Type Parsing

If a setting is defined in PYTTING_SETTINGS_MODULE and overridden using an environment variable, Pyttings will attempt to parse the new value to match the type of the original setting. For example:

# myapp/settings.py
DEBUG = True  # Boolean
timeout = 30  # Integer
export PYTTING_DEBUG="False"
export PYTTING_TIMEOUT="60"

Pyttings will automatically convert PYTTING_DEBUG to False (boolean) and PYTTING_TIMEOUT to 60 (integer), ensuring type consistency.

Contributing

Contributions are welcome! If you'd like to contribute to Pyttings, please follow these steps:

  1. Fork the repository on GitHub.
  2. Create a new branch for your feature or bugfix.
  3. Make your changes and ensure tests pass.
  4. Submit a pull request with a clear description of your changes.

Please ensure your code follows the project's style and includes appropriate tests. See the Makefile.


License

Pyttings is licensed under the MIT License. See the LICENSE file for details.

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

pyttings-1.1.0.tar.gz (4.6 kB view details)

Uploaded Source

Built Distribution

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

pyttings-1.1.0-py3-none-any.whl (5.6 kB view details)

Uploaded Python 3

File details

Details for the file pyttings-1.1.0.tar.gz.

File metadata

  • Download URL: pyttings-1.1.0.tar.gz
  • Upload date:
  • Size: 4.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for pyttings-1.1.0.tar.gz
Algorithm Hash digest
SHA256 878b1d62c89a11c1f98e6ebdbc55d26d647bed45b909a0613889b97cdb2b1b1f
MD5 3e18f6e0a23b4f7879c6918581a1a80e
BLAKE2b-256 740f4395db604b762820eed651eeec138ca5fa4ce7de6826feb54c328762262c

See more details on using hashes here.

File details

Details for the file pyttings-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: pyttings-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 5.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for pyttings-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ec4bd26751e6a92bd80411d92938331dfab88bb4d668078951b57b99404da4ce
MD5 f74cf1621d64ef8658e770f34fa2b3e1
BLAKE2b-256 73899088ac11bc03c30a1fa620441042bde3cade9af333d484dbc9f62b74c2cf

See more details on using hashes here.

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