Skip to main content

pkgsettings

image image image image image image image

Goal

The goal of this package is to offer an easy, generic and extendable way of configuring a package.

Installation

$ pip install pkgsettings

Usage

from pkgsettings import Settings

# Create the settings object for your package to use
settings = Settings()

# Now let's define the default settings
settings.configure(hello='World', debug=False)

By calling the configure you actually inject a layer of settings. When requesting a setting it will go through all layers until it finds the requested key.

Now if someone starts using your package it can easily modify the active settings of your package by calling the configure again.

from my_awesome_package.conf import settings

# Lets change the configuration here
settings.configure(debug=True)

Now from within your package you can work with the settings like so:

from conf import settings

print(settings.debug) # This will print: True
print(settings.hello) # This will print: World

It is also possible to pass an object instead of kwargs. The settings object will call getattr(ur_object, key) An example below:

class MySettings(object):
    def __init__(self):
        self.debug = True

settings = Settings()
settings.configure(MySettings())
print(settings.debug) # This will print: True

More advanced usage

The settings object can also be used as context manager:

with settings(debug=True):
    print(settings.debug) # This will print: True

print(settings.debug) # This will print: False

Additionally you can also use this as a decorator:

@settings(debug=True)
def go()
    print(settings.debug) # This will print: True

go()

print(settings.debug) # This will print: False

Prefixed Settings

If a group of settings share a common prefix, you can make use of the PrefixedSettings class and pass the desired prefix as an argument, together with the main settings instance. All attributes will be automatically prefixed when accessed.

from pkgsettings import PrefixedSettings, Settings

# First create the settings object for your package to use
settings = Settings()

# Suppose some of your settings are all prefixed with 'FOO'
settings.configure(FOO_a='a', FOO_b='b', c='c', debug=False)

# Create a PrefixedSettings instance with the desired prefix
foo_settings = PrefixedSettings(settings, 'FOO_')

foo_settings.a # This will print: a
foo_settings.b # This will print: b

foo_settings.c # This will raise an AttributeError

Release files for pkgsettings 1.1.1

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

Source distribution (sdist)

Source distribution for pkgsettings 1.1.1
File Size Uploaded
pkgsettings-1.1.1.tar.gz 22.5 kB Details

Built distribution (wheel)

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

Total release size: 31.4 kB

Release files / pkgsettings-1.1.1.tar.gz

Download URL pkgsettings-1.1.1.tar.gz
Size 22.5 kB
Tags Source
SHA-256 checksum
How to use checksums
89a66fd03a7371a8b826b64cdc022ba5aab8f70cb3422b0ca4bab0b5e6a5043b
BLAKE2b-256 checksum
How to use checksums
9513c7e0cf5f6fc23781d130066cc420c06bd69ab4e5c1f1f615d6f056156394
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.11.3

Release files / pkgsettings-1.1.1-py3-none-any.whl

Download URL pkgsettings-1.1.1-py3-none-any.whl
Size 8.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2352914c11eacd9a07d89611ed7581862befef644decec05ceb13fdecd0ba4ae
BLAKE2b-256 checksum
How to use checksums
9a24c63bdb0de15bce0f11cb4907ee3b83a6847b7d1a4e4f3905babd22d90ef0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.11.3

Release history Release notifications | RSS feed

This release

1.1.1 This release

2 release files

1.1.0

2 release files

1.0.0

2 release files

0.12.0

1 release file

0.11.0

1 release file

0.10.1

1 release file

0.10.0

1 release file

0.9.3

1 release file

0.9.2

1 release file

0.9.1

1 release file

0.9.0

1 release file

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