click is a framework to simplify writing composable commands for command-line tools. This package extends the click functionality by adding support for commands that use configuration files.
EXAMPLE:
A configuration file, like:
# -- FILE: foo.ini
[foo]
flag = yes
name = Alice and Bob
numbers = 1 4 9 16 25
filenames = foo/xxx.txt
bar/baz/zzz.txt
[person.alice]
name = Alice
birthyear = 1995
[person.bob]
name = Bob
birthyear = 2001
can be processed with:
# EXAMPLE:
# -- FILE: example_command_with_configfile.py (ALL PARTS: simplified)
from click_configfile import ConfigFileReader, Param, SectionSchema
from click_configfile import matches_section
import click
class ConfigSectionSchema(object):
"""Describes all config sections of this configuration file."""
@matches_section("foo")
class Foo(SectionSchema):
name = Param(type=str)
flag = Param(type=bool, default=True)
numbers = Param(type=int, multiple=True)
filenames = Param(type=click.Path(), multiple=True)
@matches_section("person.*") # Matches multiple sections
class Person(SectionSchema):
name = Param(type=str)
birthyear = Param(type=click.IntRange(1990, 2100))
class ConfigFileProcessor(ConfigFileReader):
config_files = ["foo.ini", "foo.cfg"]
config_section_schemas = [
ConfigSectionSchema.Foo, # PRIMARY SCHEMA
ConfigSectionSchema.Person,
]
# -- SIMPLIFIED STORAGE-SCHEMA:
# section:person.* -> storage:person.*
# section:person.alice -> storage:person.alice
# section:person.bob -> storage:person.bob
# -- ALTERNATIVES: Override ConfigFileReader methods:
# * process_config_section(config_section, storage)
# * get_storage_name_for(section_name)
# * get_storage_for(section_name, storage)
# -- COMMAND:
CONTEXT_SETTINGS = dict(default_map=ConfigFileProcessor.read_config())
@click.command(context_settings=CONTEXT_SETTINGS)
@click.option("-n", "--number", "numbers", type=int, multiple=True)
@click.pass_context
def command_with_config(ctx, numbers):
# -- ACCESS ADDITIONAL DATA FROM CONFIG FILES: Using ctx.default_map
for person_data_key in ctx.default_map.keys():
if not person_data_key.startswith("person."):
continue
person_data = ctx.default_map[person_data_key]
process_person_data(person_data) # as dict.
Metadata
Release files for click-configfile 0.2.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 |
|---|---|---|---|---|
| click-configfile-0.2.3.tar.gz | 62.5 kB | Without provenance | Details for click-configfile-0.2.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| click_configfile-0.2.3-py2.py3-none-any.whl | Python 3, Python 2 | none | any | Details for click_configfile-0.2.3-py2.py3-none-any.whl |
Total release size: 72.5 kB
Release files / click-configfile-0.2.3.tar.gz
| Download URL | click-configfile-0.2.3.tar.gz |
|---|---|
| Size | 62.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
95beec13bee950e98f43c81dcdabef4f644091559ea66298f9dadf59351d90d1
|
|
BLAKE2b-256 checksum How to use checksums |
5a2b722c718db0f44e6927767aa422c73a77eaf333138e0a4201ca9b1f72aa2d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Release files / click_configfile-0.2.3-py2.py3-none-any.whl
| Download URL | click_configfile-0.2.3-py2.py3-none-any.whl |
|---|---|
| Size | 10.0 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
af2ae7123af57d850cd18edd915893e655b6b1bc30d1302fd040b1059bec073d
|
|
BLAKE2b-256 checksum How to use checksums |
c4c4a2f9be9e758ec758542fc0348109c886bb840f88d25f05cb76ed01c07c84
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for click-configfile 0.2.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.