Skip to main content

A simple package for rapidly developing system settings.

Project description

Settings

Sejings is meant to be a quick and simple tool to rapidly integrate project settings. This was inspired by a desire to work with a solution similar to MatPlotLib's rcParams and to improve on the developer experience and developing speed by avoiding None checks.

This is the development experience I'm trying to avoid:

def add(*nums, cache=None, cache_path=None):
    
    if cache is None:
        cache = settings['cache']
    if cache_path is None:
        cache_path = settings['cache.path']
    
    result = sum(nums)
    
    if cache: # True
        save_to_cache(result, cache_path) #'/some/dir/path'
    
    return result

Obviously dictionaries would be computationally the fastest way to accomplish settings. This project is meant to be friendly to developers consuming packages and to encourage rapid development over absolute runtime speed. We're using Python after all, right?

Usage

Import settings and create the settings you need:

from sejings import settings

settings.cache = True
settings.cache.path = '/some/dir/path'

To evaluate settings passed into a function as an argument use the @extract_settings decorator. This will evaluate all settings in the function definition and in the arguments being passed into the function:

from settings import extract_settings

@extract_settings
def add(*nums, cache=settings.cache, cache_path=settings.cache.path):
    result = sum(nums)
    
    if cache: # True
        save_to_cache(result, cache_path) #'/some/dir/path'
    
    return result

A branch is also evaluated when an endpoint is called.

assert settings.cache()
assert settings.cache.path() == '/some/dir/path'

def add(*nums, cache=settings.cache, cache_path=settings.cache.path):
    result = sum(nums)
    
    if cache(): # True
        save_to_cache(result, cache_path()) #'/some/dir/path'
    
    return result

In some cases defining arguments as a Settings object may be desired. This is accomplished by adding the argument name to the @extract_settings arguments.

@extract_settings('cache')
def add(*nums, cache=settings.cache):
    result = sum(nums)
    
    if cache(): # True
        save_to_cache(result, cache.path()) #'/some/dir/path'
    
    return result

@TODO

  • I'm exploring options right now to allow methods to be called directly on self._val but am weighing the pros and cons. The SettingsNumber class published is something I'm exploring and should not be depended on as it may change.
  • Context manager
  • Copy functionality
  • Iteration
  • getitem, setitem
  • IO to file. Look into integration with configparser.

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

sejings-0.0.2.tar.gz (4.4 kB view details)

Uploaded Source

File details

Details for the file sejings-0.0.2.tar.gz.

File metadata

  • Download URL: sejings-0.0.2.tar.gz
  • Upload date:
  • Size: 4.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.41.0 CPython/3.7.6

File hashes

Hashes for sejings-0.0.2.tar.gz
Algorithm Hash digest
SHA256 75f014fc31a154f2dd91bd8069578436abc8a5c3e1a03a4fe22a932bb60bac93
MD5 e7b577a65273d5aa7d7d6b1cba7f439c
BLAKE2b-256 4ed87a1fc8d74ce33adcfac22c2260e769c29bd40ea7ca5f20d07f61d6563349

See more details on using hashes here.

Supported by

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