Pyonf
Easy configuration parsing for your Python script, using command line argument or YAML file.
Quickstart
Content of myapp.py:
#!/usr/bin/env python
from pyonf import pyonf
default_configuration = {
'user': 'foo',
'password': 'changeme',
'debug': False
}
conf = pyonf(default_configuration)
print(conf)
Set configuration from command line:
$ ./myapp.py --user simfu -d
{'debug': True, 'password': 'changeme', 'user': 'simfu'}
Or from YAML configuration file myconfig.yml:
user: simfu
password: secretpass
gives:
$ ./myapp.py myconfig.yml
{'debug': False, 'password': 'secretpass', 'user': 'simfu'}
Get script usage:
$ ./myapp.py --help
usage: myapp.py [-h] [--debug] [--password PASSWORD] [--user USER] [conf_file]
Configuration file:
conf_file Path to YAML configuration file (optional)
Options:
-h, --help show this help message and exit
--debug, -d turn on "debug"
--password PASSWORD, -p PASSWORD
set "password" value, as str (default is changeme)
--user USER, -u USER set "user" value, as str (default is foo)
Features
- Automatically build a command line or configuration file parser by providing a default configuration
- Support for complex configuration schemes (e.g.: lists, dict of dict of ...), mandatory options
- Default configuration can be provided as Python dict object, YAML string or YAML file
- Configuration can be converted to global variables
- Compatible with Python 2 & 3
More Examples
Automatic argparsing: help message, short and long parameters
$ ./myapp.py --help
usage: myapp.py [-h] [--debug] [--password PASSWORD] [--user USER] [conf_file]
Configuration file:
conf_file Path to YAML configuration file (optional)
Options:
-h, --help show this help message and exit
--debug, -d turn on "debug"
--password PASSWORD, -p PASSWORD
set "password" value, as str (default is changeme)
--user USER, -u USER set "user" value, as str (default is foo)
$ ./myapp.py -u simfu
{'debug': False, 'password': 'changeme', 'user': 'simfu'}
$ ./myapp.py --user simfu
{'debug': False, 'password': 'changeme', 'user': 'simfu'}
Use both configuration file and command line argument (the latter takes precedence)
$ ./myapp.py myconfig.yml -d
{'debug': True, 'password': 'secretpass', 'user': 'simfu'}
Multiple input for default configuration
# Using a dict
default_configuration = {
'user': 'foo',
'password': 'changeme',
'debug': False
}
# Using a YAML String
default_configuration = """
user: foo
password: changeme
debug: false
"""
conf = pyonf(default_configuration)
print(conf)
# Using a YAML file
default_configuration = "/etc/myapp.conf"
conf = pyonf(default_configuration)
print(conf)
Smart parsing of option type
default_configuration = """
user: foo
password: changeme
debug: false
level: 3
"""
conf = pyonf(default_configuration)
print(conf)
i.e.:
$ ./myapp.py -l 4 # OK
$ ./myapp.py -l quatre # Will not work, level needs to be an integer
# Boolean option does not need argument, its value will be switched
$ ./myapp.py -d
Complex configuration scheme
default_configuration = """
user: foo
password: changeme
suboptions:
param1: value1
param2: value2
"""
conf = pyonf(default_configuration)
print(conf)
set "sub-keys" with:
$ ./myapp.py --suboptions-param1 my_new_value
Mandatory options:
default_configuration = """
user: foo
password: changeme
debug: false
level: 3
"""
conf = pyonf(default_configuration, mandatory_opts = ['user', 'password'])
print(conf)
you have to define user and password option:
$ ./my_app.py
Error: "user" option is not set
Convert parsed configuration to global variables:
default_configuration = """
user: foo
password: changeme
debug: false
level: 3
"""
pyonf(default_configuration, as_global_vars=True)
print(user, password)
i.e.:
$ ./myapp.py -p secret
foo secret
Metadata
Release files for pyonf 0.3
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 |
|---|---|---|---|---|
| pyonf-0.3.tar.gz | 5.0 kB | Without provenance | Details for pyonf-0.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pyonf-0.3-py3-none-any.whl | Python 3 | none | any | Details for pyonf-0.3-py3-none-any.whl |
Total release size: 9.7 kB
Release files / pyonf-0.3.tar.gz
| Download URL | pyonf-0.3.tar.gz |
|---|---|
| Size | 5.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
763e585b5a2e7cee373a344214017ecf6889a28cdeb1a73c2234291a71cedfca
|
|
BLAKE2b-256 checksum How to use checksums |
e7a5595e769c2c6adf6beb256fa51a8949000f8624741273472e3dcf16ff37d6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.3.0 pkginfo/1.4.2 requests/2.25.1 setuptools/52.0.0 requests-toolbelt/0.9.1 tqdm/4.57.0 CPython/3.9.2
|
Release files / pyonf-0.3-py3-none-any.whl
| Download URL | pyonf-0.3-py3-none-any.whl |
|---|---|
| Size | 4.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
2bed95e8a2f38d5344275cff11011b556e8f721f440198f56165e003df0ba858
|
|
BLAKE2b-256 checksum How to use checksums |
db7251e6c749c6edb45e61b1de8eea9767c252aae9d2e60e865b9d15a307db00
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.3.0 pkginfo/1.4.2 requests/2.25.1 setuptools/52.0.0 requests-toolbelt/0.9.1 tqdm/4.57.0 CPython/3.9.2
|
Security for pyonf 0.3
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.