Skip to main content

Python package to ease the configuration of packages

Project description










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


$ pip install pkgsettings


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

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()
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:

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


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

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

pkgsettings-1.0.0.tar.gz (18.2 kB view hashes)

Uploaded source

Built Distribution

pkgsettings-1.0.0-py3-none-any.whl (4.6 kB view hashes)

Uploaded py3

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page