Skip to main content

Extend parser is set of ConfigParser extensions. Get and Include extensions are added to one class ExtendParser. For more details see source code, or use help.

copyright:

2018, see AUTHORS for more details

license:

BSD, see LICENSE for more details

Library

ExtendParser

>>> from extendparser import ExtendParser
>>> cp = ExtendParser()

Include

Include class can append content from other configuration files. Let’s have these configuration files:

# test.ini
[main]
string = value
.include numbers.ini
# numbers.ini
integer = 42
.include const.ini
# const.ini
pi = 3.14

Here is the string buffer which ConfiguratinParser will read:

# test.ini
[main]
string = value
# numbers.ini
integer = 42
# const.ini
pi = 3.14

Get

Get class has two smart methods get_option and get_section to get value(s) in any type you want.

>>> from extendparser.get import Get
>>> cp = Get()
>>> print(cp.get_option("test", "number", target=int, fallback=1))
1
>>> print(cp.get_option("test", "list", target=list, fallback=["a"],
...                      delimiter=','))
['a']
>>> cp.add_section("test")
>>> cp.set("test", "tuple", "a:b:c")
>>> print(cp.get_option("test", "tuple", target=tuple, delimiter=':'))
('a', 'b', 'c')
>>> print(cp.get_section("test", (("tuple", tuple, tuple(), ':'),
...                               ("string", str, "value"))))
{'tuple': ('a', 'b', 'c'), 'string': 'value'}

Environment

Environ module has two classes, which extend ConfigParser to read environment variables. There is EnvironFirst class, which read environment variables first, and then use original get method.

>>> from os import environ
>>> from configparser import ConfigParser
>>> from extendparser.environ import EnvironFirst
>>> cp = EnvironFirst()
>>> cp.add_section("test")
>>> cp.getint("test", "number", fallback=1)
1
>>> cp.set("test", "number", "7")
>>> cp.getint("test", "number")
7
>>> environ["TEST_NUMBER"] = "42"
>>> cp.getint("test", "number")
42

Next EnvironLast class use environment variable as fallback for original get method.

>>> from os import environ
>>> from configparser import ConfigParser
>>> from extendparser.environ import EnvironLast
>>> cp = EnvironLast()
>>> cp.add_section("test")
>>> cp.getfloat("test", "float", fallback=1.0)
1.0
>>> environ["TEST_FLOAT"] = "42"
>>> cp.getfloat("test", "float", fallback=1)
42.0
>>> cp.set("test", "float", "3.14")
>>> cp.getfloat("test", "float")
3.14

Installation

~$ pip install extendparser

Metadata

Release files for extendparser 0.3.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for extendparser 0.3.1
File Size Uploaded Provenance Actions
extendparser-0.3.1.tar.gz 8.7 kB Without provenance Details for extendparser-0.3.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for extendparser 0.3.1
File Interpreter ABI Platform Actions
extendparser-0.3.1-py3-none-any.whl Python 3 none any Details for extendparser-0.3.1-py3-none-any.whl

Total release size: 20.1 kB

Release files / extendparser-0.3.1.tar.gz

Download URL extendparser-0.3.1.tar.gz
Size 8.7 kB
Tags Source
SHA-256 checksum
How to use checksums
91bd3117a48806aead792200aff889ee76b35fe305c3398021b3362ddc0ec2ac
BLAKE2b-256 checksum
How to use checksums
2fc44fa9b3d5d7bdee4b8eac324832d783dfdcd813b72bb86a5c8b5e117afd31
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/54.0.0 requests-toolbelt/0.9.1 tqdm/4.58.0 CPython/3.7.1

Release files / extendparser-0.3.1-py3-none-any.whl

Download URL extendparser-0.3.1-py3-none-any.whl
Size 11.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f22dd3e19cabf4cb0108ab194d1251498167cd53e369ec6bb7e6311eb3765780
BLAKE2b-256 checksum
How to use checksums
c616070ec7b689e84b2c6d224733d207eef8e434340b2a9a82c8244ef93516cd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/54.0.0 requests-toolbelt/0.9.1 tqdm/4.58.0 CPython/3.7.1

Security for extendparser 0.3.1

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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page