optini
Python class to get options from command line and config file
Free software: MIT license
Documentation: https://optini.readthedocs.io.
Features
Aggressively conventional defaults
- Collect configuration from command line, config file, and defaults
Configuration hierarchy: command line > config file > defaults
- Interface is a module-level variable: optini.opt
Module-level interface allows libraries to access config
- Access config options through module-level dotmap interface
Example: optini.opt.verbose
- Derives command line options from option names
Example: “verbose” => -v and –verbose
- Single flag to support (mostly) conventional logging options
(-v, -d, -q, -L, -F LOGFILE)
Single flag to support I/O options (-i input and -o output)
Supports top-level ini section without a header
Uses standard libraries under the hood (logging, argparse, configparser)
Limitations
Only top-level code (such as UI script) should initialize Config
Examples
Define one boolean option, someopt, which defaults to false; users can specify -s at the command line, or put someopt = true in the config file.
import optini
optini.spec.someopt.help = 'Set a flag'
# implies -s and --someopt command line options
desc = 'This code does a thing'
optini.Config(appname='myapp', file=True, desc=desc)
if optini.opt.someopt:
print("someopt flag is set")
Config file defaults to ~/.<appname>.ini
Enable logging config:
import logging
import optini
optini.Config(appname='something', logging=True)
# the verbose (-v) option enables info messages
logging.info('this is an info message')
# the debug (-d) option enables debug messages
logging.debug('this is a debug message')
# the Log (-L) option writes logs to file (default: <appname>.log)
Option Specification Format
Nested data structure (either dict or dotmap is valid)
The top level key is the option name
- To configure each option, specify second level keys:
- helpstr, default=None
for argparse usage message, default config file comments
- typetype, default=bool
type hint for parsers
Supported: bool, str, int, float
- default, default=None
the default value for the option
- required, default=False
Declare the option mandatory at the command line
- shortstr
Short form command line option (example: -v)
- longstr
Long form command line option (example: –verbose)
- configfilebool
Specify False for command line only options
Second level keys, apart from configfile, are passed to argparse
Credits
This package was created with Cookiecutter and the audreyr/cookiecutter-pypackage project template.
Metadata
Release files for optini 0.5.0
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 |
|---|---|---|---|---|
| optini-0.5.0.tar.gz | 17.3 kB | Without provenance | Details for optini-0.5.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| optini-0.5.0-py3-none-any.whl | Python 3 | none | any | Details for optini-0.5.0-py3-none-any.whl |
Total release size: 26.9 kB
Release files / optini-0.5.0.tar.gz
| Download URL | optini-0.5.0.tar.gz |
|---|---|
| Size | 17.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c57c7505d8cf8e3d40b794a843706a28f1e845cb0972325b250ff1d99b3ddfb4
|
|
BLAKE2b-256 checksum How to use checksums |
2a62de20e95dce53fd22d7c4ffec73bc0cbec996b889927364de0592977a3965
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
python-requests/2.31.0
|
Release files / optini-0.5.0-py3-none-any.whl
| Download URL | optini-0.5.0-py3-none-any.whl |
|---|---|
| Size | 9.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
55645d4c3797a5bd276db0380fc112493dc1c65e0cc52c855397246b67b7fded
|
|
BLAKE2b-256 checksum How to use checksums |
a17af24516225eab0c6209c66f45b337cf2d494847305e3eed978a3388aef192
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
python-requests/2.31.0
|
Security for optini 0.5.0
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.