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 .
Metadata
Release files for lazycon 0.6.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| lazycon-0.6.4.tar.gz | 22.0 kB | Without provenance | Details for lazycon-0.6.4.tar.gz |
Release files / lazycon-0.6.4.tar.gz
| Download URL | lazycon-0.6.4.tar.gz |
|---|---|
| Size | 22.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
26e03608111c109922a74c45c802fd0d1d06604918028069139105416b8ab7c3
|
|
BLAKE2b-256 checksum How to use checksums |
726c4bc1d3bc42b3241617991c8618780d64ff003b926fae96016017649791c1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.9.20
|
Security for lazycon 0.6.4
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.