Skip to main content

Updated configparser from Python 3.8 for Python 2.6+.

Project description

https://img.shields.io/pypi/v/configparser.svg https://img.shields.io/pypi/pyversions/configparser.svg tests Code style: Black https://readthedocs.org/projects/configparser/badge/?version=latest https://img.shields.io/badge/skeleton-2021-informational https://tidelift.com/badges/package/pypi/configparser

This package is a backport of the refreshed and enhanced ConfigParser from later Python versions. To use the backport instead of the built-in version, simply import it explicitly as a backport:

from backports import configparser

To use the backport on Python 2 and the built-in version on Python 3, use the standard invocation:

import configparser

For detailed documentation consult the vanilla version at http://docs.python.org/3/library/configparser.html.

Why you’ll love configparser

Whereas almost completely compatible with its older brother, configparser sports a bunch of interesting new features:

  • full mapping protocol access (more info):

    >>> parser = ConfigParser()
    >>> parser.read_string("""
    [DEFAULT]
    location = upper left
    visible = yes
    editable = no
    color = blue
    
    [main]
    title = Main Menu
    color = green
    
    [options]
    title = Options
    """)
    >>> parser['main']['color']
    'green'
    >>> parser['main']['editable']
    'no'
    >>> section = parser['options']
    >>> section['title']
    'Options'
    >>> section['title'] = 'Options (editable: %(editable)s)'
    >>> section['title']
    'Options (editable: no)'
  • there’s now one default ConfigParser class, which basically is the old SafeConfigParser with a bunch of tweaks which make it more predictable for users. Don’t need interpolation? Simply use ConfigParser(interpolation=None), no need to use a distinct RawConfigParser anymore.

  • the parser is highly customizable upon instantiation supporting things like changing option delimiters, comment characters, the name of the DEFAULT section, the interpolation syntax, etc.

  • you can easily create your own interpolation syntax but there are two powerful implementations built-in (more info):

    • the classic %(string-like)s syntax (called BasicInterpolation)

    • a new ${buildout:like} syntax (called ExtendedInterpolation)

  • fallback values may be specified in getters (more info):

    >>> config.get('closet', 'monster',
    ...            fallback='No such things as monsters')
    'No such things as monsters'
  • ConfigParser objects can now read data directly from strings and from dictionaries. That means importing configuration from JSON or specifying default values for the whole configuration (multiple sections) is now a single line of code. Same goes for copying data from another ConfigParser instance, thanks to its mapping protocol support.

  • many smaller tweaks, updates and fixes

A few words about Unicode

configparser comes from Python 3 and as such it works well with Unicode. The library is generally cleaned up in terms of internal data storage and reading/writing files. There are a couple of incompatibilities with the old ConfigParser due to that. However, the work required to migrate is well worth it as it shows the issues that would likely come up during migration of your project to Python 3.

The design assumes that Unicode strings are used whenever possible [1]. That gives you the certainty that what’s stored in a configuration object is text. Once your configuration is read, the rest of your application doesn’t have to deal with encoding issues. All you have is text [2]. The only two phases when you should explicitly state encoding is when you either read from an external source (e.g. a file) or write back.

Versioning

This project uses semver to communicate the impact of various releases while periodically syncing with the upstream implementation in CPython. The history serves as a reference indicating which versions incorporate which upstream functionality.

Prior to the 4.0.0 release, another scheme was used to associate the CPython and backports releases.

Maintenance

This backport was originally authored by Łukasz Langa, the current vanilla configparser maintainer for CPython and is currently maintained by Jason R. Coombs:

For Enterprise

Available as part of the Tidelift Subscription.

This project and the maintainers of thousands of other packages are working with Tidelift to deliver one enterprise subscription that covers all of the open source you use.

Learn more.

Security Contact

To report a security vulnerability, please use the Tidelift security contact. Tidelift will coordinate the fix and disclosure.

Conversion Process

This section is technical and should bother you only if you are wondering how this backport is produced. If the implementation details of this backport are not important for you, feel free to ignore the following content.

The project takes the following branching approach:

  • The 3.x branch holds unchanged files synchronized from the upstream CPython repository. The synchronization is currently done by manually copying the required files and stating from which CPython changeset they come.

  • The main branch holds a version of the 3.x code with some tweaks that make it compatible with older Pythons. Code on this branch must work on all supported Python versions. Test with tox or in CI.

The process works like this:

  1. In the 3.x branch, run pip-run -- sync-upstream.py, which downloads the latest stable release of Python and copies the relevant files from there into their new locations and then commits those changes with a nice reference to the relevant upstream commit hash.

  2. Check for new names in __all__ and update imports in configparser.py accordingly. Optionally, run the tests on a late Python 3. Commit.

  3. Merge the new commit to main. Run tests. Commit.

  4. Make any compatibility changes on main. Run tests. Commit.

  5. Update the docs and release the new version.

Footnotes

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

configparser-5.2.0.tar.gz (67.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

configparser-5.2.0-py3-none-any.whl (19.7 kB view details)

Uploaded Python 3

File details

Details for the file configparser-5.2.0.tar.gz.

File metadata

  • Download URL: configparser-5.2.0.tar.gz
  • Upload date:
  • Size: 67.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.0 importlib_metadata/4.8.2 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.0

File hashes

Hashes for configparser-5.2.0.tar.gz
Algorithm Hash digest
SHA256 1b35798fdf1713f1c3139016cfcbc461f09edbf099d1fb658d4b7479fcaa3daa
MD5 b91f5fe1d5aa8e4d3793597eaff0ea29
BLAKE2b-256 02a85fae273a45a3e4e34ea560c99a4843fe2d9fc6fb691de064dc9c72c46e57

See more details on using hashes here.

File details

Details for the file configparser-5.2.0-py3-none-any.whl.

File metadata

  • Download URL: configparser-5.2.0-py3-none-any.whl
  • Upload date:
  • Size: 19.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.0 importlib_metadata/4.8.2 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.0

File hashes

Hashes for configparser-5.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e8b39238fb6f0153a069aa253d349467c3c4737934f253ef6abac5fe0eca1e5d
MD5 69bab6f43cd4375830a54a53a50129fa
BLAKE2b-256 2baf0e28626b47c84172a112397f034bb1b6349960ca6e0fe7c96666e0ccae69

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page