Skip to main content

Easy config files in pure Python

Project description

codecov pypi License PyPI - Downloads GitHub branch checks state

Easy config files in pure Python!

What you can do directly in your configs:

  • define constants
  • define functions
  • use import statements
  • call functions and apply arithmetic operations
  • a static read-only scope
  • static checking: cycles detection, undefined variables detection

Install

pip install lazycon

Features

Basic

Let's define a config file example.config and see what it can do

# define constants
num_steps = 100
database_table = 'user_data'

# or more complex structures
parameters = {
    'C': 10,
    'metric': 'roc_auc',
}
values_to_try = [0, 1, 2, 3, 4]

# you can use and call builtins
some_range = list(range(100))
# or even comprehensions!
squares = [i ** 2 for i in range(20)]

Now let's load our config from python

from lazycon import load

config = load('example.config')
print(config.database_table)
# 'user_data'

Need to change an existing config? No problem!

from lazycon import load

config = load('example.config')
config.update(
    database_table='customer_data',
    some_range=[1, 3, 5],
)
config.dump('updated.config')

Advanced

Python-based configs can do so much more! Let's create another advanced.config:

# combine config entries
x = 1
y = 2
z = x + y

# define lambdas
callback = lambda value: 1 if value == 0 else (1 / value)


# or more complex functions
def strange_normalize(a, b):
    temp = a ** 2 + b ** 2
    return a / temp, b / temp

You can import from other python libraries:

import numpy as np
from math import sqrt

const = np.pi / np.e
proportions = sqrt(2)

Or even other configs!

# import from `example.config` defined above
from .example import *

extended_values_to_try = values_to_try + [101, 102]

Contribute

Just get the project from GitHub and modify it how you please!

git clone https://github.com/maxme1/lazycon.git
cd lazycon
pip install -e .

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

lazycon-0.6.1.tar.gz (16.8 kB view details)

Uploaded Source

File details

Details for the file lazycon-0.6.1.tar.gz.

File metadata

  • Download URL: lazycon-0.6.1.tar.gz
  • Upload date:
  • Size: 16.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.16

File hashes

Hashes for lazycon-0.6.1.tar.gz
Algorithm Hash digest
SHA256 99189f010485553744e79e00324281a0c74427d8939bf5a88516eb1e04a22b5b
MD5 a86cd31ed1709a3474d32b10f0b8b449
BLAKE2b-256 90c0ecd1f776e99da8082147086a370be63bdaec3da3401ea70606f33ebbc32f

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