Skip to main content

ConfigRW

ConfigRW is a simple python module which read and write config files based on key-value or INI-structure.

Key features

  • Maximum preserves formatting of the source file (indents, spaces, comments, etc)
  • Support non-section (for access for simple config files based on key-value)
  • Inserting an option on an arbitrary string in the section
  • Support multiple values of option
  • Support options without values
  • Support comments in a section
  • Support indentation for options, values
  • Secure file rewriting. Using *.new file on write, then renamed to original filename

Installation

Installation package to user python-library directory:

$ pip install --user configrw

Or you can install package to global system directory of python libraries (not recommended):

$ sudo pip install configrw

Documentation

You can find a full manual on how to use ConfigRW at readthedocs

Quick start

In next examples we will use the following INI file:

# This is comment
this is option = this is value
second option  = -100

[ SECTION1 ] # comment
    option1 = 100
    option2 = 200
    # comment
    option3 = 1.2

[ section2 ]
    param1 = 'str'
    param2 = 0 # comment
    parameter_without_value

[section3]
    extensions =
        # comment1
        ext1
        # comment2
        ext2
        ext3

Access to non-section area

This is features needed if you want use simple key-value of config file

from configrw import Config

config = Config.from_file('/path/to/file')

section = config[None]             # Getting non-section
value = section['this is option']  # Getting the value
section['this is option'] = None   # Setting the value
del section['second option']       # Deleting the option

Access to section area

This is features needed if you want use INI config file

value = config['SECTION1']['option2']       # Getting the value
config['SECTION1']['option2'] = 0           # Setting the value
config['SECTION1']['option3'] = 300         # Adding new option to section

config['section3']['extensions'].append('ext4')     # Adding new value to multiple values
config['section3']['extensions'].insert('ext0', 0)  # Inserting new value
config['section3']['extensions'][0] = 'extension0'  # Changing single value of multiple values

config.write('/path/to/file')               # Saving config to file

# Render config to screen
for line in config.to_text():
    print(line)

INI-file after changes:

# This is comment
this is option

[ SECTION1 ] # comment
    option1 = 100
    option2 = 0
    # comment
    option3 = 300

[ section2 ]
    param1 = 'str'
    param2 = 0 # comment
    parameter_without_value

[section3]
    extensions =
        extension0
        # comment1
        ext1
        # comment2
        ext2
        ext3
        ext4

Metadata

Release files for configrw 1.1.0

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

Source distribution (sdist)

Source distribution for configrw 1.1.0
File Size Uploaded
configrw-1.1.0.tar.gz 5.5 kB Details

Release files / configrw-1.1.0.tar.gz

Download URL configrw-1.1.0.tar.gz
Size 5.5 kB
Tags Source
SHA-256 checksum
How to use checksums
7874e5c4ae48c19af945f6ad1cc9a713e56911f0ca5b77e8a12c99106101bcff
BLAKE2b-256 checksum
How to use checksums
0d774cca6c5aabaaee9224d533199026cb9af7e287870ee0d73445cd9282ca99
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.3

Release history Release notifications | RSS feed

This release

1.1.0 This release

1 release file

1.0.0

1 release file

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