Mojo-ini v0.2.0 - Native INI Parser (Initial release)

mojo-ini v0.2.0 - Native INI Parser

From the author (@mjboothaus) of mojo-dotenv and mojo-toml comes mojo-ini, a native INI file parser and writer for Mojo with Python configparser compatibility and zero dependencies.

What it does

Parses and writes INI configuration files into native Mojo structures:

  • Classic INI format: [sections] and key = value pairs
  • Comments: # and ; styles
  • Multiline values (indented continuation)
  • Inline comments
  • File I/O helpers (parse_file, write_file)
  • Clear error messages with line/column context
  • 46 tests ensuring reliability

INI is a basic format using [sections] and simple key=value pairs for flat configuration settings, introduced in the late 1980s with early Microsoft Windows (popularised in Windows 3.0, 1990).

Installation

git clone https://github.com/DataBooth/mojo-ini.git
cd mojo-ini
pixi run test-all

Coming soon to the modular-community channel.

Usage

Parsing:

from ini import parse

fn main() raises:
    var config = parse("""
        [Database]
        host = localhost
        port = 5432
        user = admin
    """)

    print(config["Database"]["host"])  # "localhost"
    print(config["Database"]["port"])  # "5432"

Writing:

from ini import to_ini

fn main() raises:
    var data = Dict[String, Dict[String, String]]()
    data["App"] = Dict[String, String]()
    data["App"]["name"] = "MyApp"
    data["App"]["version"] = "1.0"

    var ini_text = to_ini(data)
    print(ini_text)
    # [App]
    # name = MyApp
    # version = 1.0

File I/O:

from ini import parse_file, write_file

fn main() raises:
    var config = parse_file("config.ini")
    config["Server"]["port"] = "8080"
    write_file("config.ini", config)

What’s in v0.2.0

  • Complete INI parser and writer (677 LOC)
  • Multiline value support (Python configparser compatible)
  • File I/O helpers for reading and writing files
  • 46 comprehensive tests across 5 test suites
  • Performance benchmarks with statistical reporting:
    • Small configs: ~9 μs parse, ~1 μs write
    • Medium configs: ~97 μs parse, ~23 μs write
    • Large configs: ~1038 μs parse, ~237 μs write
    • 7-10x faster than Python for small configs

See the CHANGELOG for full details.

Links

Python configparser Compatibility

mojo-ini aims for high compatibility with Python’s configparser:

Feature Python mojo-ini v0.2
Basic key=value :white_check_mark: :white_check_mark:
[Sections] :white_check_mark: :white_check_mark:
Multiline values :white_check_mark: :white_check_mark:
Inline comments :white_check_mark: :white_check_mark:
[DEFAULT] section :white_check_mark: :construction: Planned v0.3
Value interpolation :white_check_mark: :construction: Planned v0.3
Type converters :white_check_mark: :construction: Planned v0.3

Roadmap

Planned features for future releases:

  • [DEFAULT] section with value inheritance
  • Value interpolation %(var)s
  • ConfigParser class API with type converters
  • Case-insensitive mode

Related Projects

Together these provide comprehensive configuration file support for Mojo! :bullseye:

Acknowledgements

This project is sponsored by DataBooth, building high-performance data and AI services with Mojo.

Feedback and contributions welcome!