Skip to main content

A simple package for rapidly developing system settings.

Project description

Sejings

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

# This is the development process I'd like to change.
def add(*nums, cache=None, cache_path=None):
    if cache is None:
        cache = sejings['cache']
    if cache_path is None:
        cache_path = sejings['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 sejings. 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 sejings and create the sejings you need:

from sejings import sejings

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

To evaluate the values of sejings when calling a function use the @extract_sejings decorator. This will evaluate all sejings in the function definition and in the arguments being passed into the function:

from sejings import extract_sejings

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

A branch is evaluated when an endpoint is called.

from sejings import extract_sejings

def add(*nums, cache=sejings.cache, cache_path=sejings.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 Sejings object may be desired. This is accomplished by adding the argument name to the @extract_sejings arguments.

from sejings import extract_sejings

@extract_sejings('cache')
def add(*nums, cache=sejings.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 SejingsNumber class published is something I'm exploring and should not be depended on as it may change.
  • Context manager
  • Property decorators
  • Copy functionality
  • Iteration
  • Dictionary like functionality
  • 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.1.tar.gz (4.5 kB view details)

Uploaded Source

File details

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

File metadata

  • Download URL: sejings-0.0.1.tar.gz
  • Upload date:
  • Size: 4.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/39.1.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.6.5

File hashes

Hashes for sejings-0.0.1.tar.gz
Algorithm Hash digest
SHA256 7fc6128891c7855b7c351512083f33e5bbc611312c4529e5744771d14e901ed5
MD5 9c99add7846f052ce77ad2a794bba0c4
BLAKE2b-256 e9b2313d7780c7f146381b085615a4e0d7de1c5d2fba80eef76467d0b84ddb76

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