Skip to main content

INI Handler

This is a ini/config-file handler that preserves comments.

For various projects of mine, I prefer to provide comments within an ini file for others to know their meanings, or other options.

While ConfigParser is nice, it always removed any/all comments from the file, so this project solves that issue.

Features:

  • Preserve comments
  • Supports: "#", ":", ";" and "//" as line comments
  • Supports "line comment" and "comments behind values"
  • Custom "separator" (default: "=", but you could used: " : " just as well, or whatever else)
  • Allows toggle between: "instant save" or "on purpose"
  • May handle "lazy" (bStrict=False ; default:: bStrict=True) ini files, that do not have any "[Section]"s (this is required for the saving, wether manual or automatic)
  • Allows for fallback/non-existing config, in case a config file gets corrupted or deleted

Usage:

How to handle this class:

Available commands:

  • my_ini.export(args)
  • my_ini.get(args)
  • my_ini.get_simple(args)
  • my_ini.list_sections()
  • my_ini.list_variables(args)
  • my_ini.load_data()
  • my_ini.load_file()
  • my_ini.save()
  • my_ini.set(args)
  • my_ini.set_simple(args)

Import:

import inihandler

Initialize:

my_ini = inihandler.handler("/path/to/file")

Working with values:

# Get value:
current_value = my_ini.get("SectionName", "VariableName")
print(current_value)

# Set Value:
my_ini.set("SectionName", "VariableName", "NewValue")

Special Handling:

If you have bInstantSave=False you simply call: my_ini.save() at whatever point you want/need to save the file.

You can still use my_ini.get(section, key) or my_ini.get_simple(key) to retrieve current settings from memory.

Example File:

Here is an example of a - very chaotic, but still work-able - ini file:

# Most used comment
; But you can apply any comment style
// that fits your project

[section]
variable = some value
someting = with a comment // like this
ofCourse = this would ; work as well
sooooo = "would this ; if you" ; apply quotes

Additional Examples

  • can be found on github
  • just run py ./testfile.py to get a sample dump per example config
  • example config files are in ./test/

Metadata

Release files for inihelper 0.1.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 inihelper 0.1.1
File Size Uploaded Provenance
inihelper-0.1.1.tar.gz 17.0 kB Without provenance Details

Built distribution (wheel)

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

Total release size: 34.6 kB

Release files / inihelper-0.1.1.tar.gz

Download URL inihelper-0.1.1.tar.gz
Size 17.0 kB
Tags Source
SHA-256 checksum
How to use checksums
5bd7742be0eba90a3978d56afb175e3c4b44b0b9ddce6fcdc1a0ebe62dde3618
BLAKE2b-256 checksum
How to use checksums
ab5d7c44f25449a20cdc90ee228aca2f7c745ab2cc72147f126446cff7342665
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.3

Release files / inihelper-0.1.1-py3-none-any.whl

Download URL inihelper-0.1.1-py3-none-any.whl
Size 17.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e6cd850bdb8c867101f8f6d949285eb4cd046fc407ec2d3e2b50457dcf74d18a
BLAKE2b-256 checksum
How to use checksums
1fbb7ac06422ffa26894f73a2f9db920d5fc0f1cc6fcac860914d4aa14476fe0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.3

Security for inihelper 0.1.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.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files No provenance

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