mojo-ini ๐ฅ
January 27, 2026 ยท View on GitHub
INI file parser and writer for Mojo - Python configparser compatible
Parse and write INI configuration files in native Mojo with zero Python dependencies. Compatible with Python's configparser module for drop-in replacement in Mojo projects.
Features
- โ
Python
configparserCompatible - Drop-in replacement for Python's standard library - โ Parser & Writer - Both read and write INI files
- โ
Classic INI Support - Standard
key = valuesyntax with[sections] - โ Extended Features - Multiline values, inline comments, value interpolation
- โ Multiple Dialects - configparser (default) and classic INI modes
- โ Comprehensive Tests - Full test coverage
- โ Zero Dependencies - Pure Mojo implementation
Status: โ v0.2.0 Released - Production ready with comprehensive testing and benchmarks
Quick Start
Parsing INI Files:
from ini import parse
var config = parse("""
[Database]
host = localhost
port = 5432
user = admin
[Server]
debug = true
timeout = 30
""")
# Access values
print(config["Database"]["host"]) # localhost
print(config["Database"]["port"]) # 5432
print(config["Server"]["debug"]) # true
Writing INI Files:
from ini import to_ini
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)
# Output:
# [App]
# name = MyApp
# version = 1.0
See examples/read_example.mojo and examples/write_example.mojo for complete working examples.
Installation
Option 1: Magic Package Manager (Recommended)
magic add mojo-ini
Option 2: Git Submodule
git submodule add https://github.com/databooth/mojo-ini vendor/mojo-ini
Then in your Mojo code:
mojo -I vendor/mojo-ini/src your_app.mojo
Option 3: Direct Copy
cp -r mojo-ini/src/ini your-project/lib/ini
Usage
Basic Parsing
from ini import parse
var config = parse("""
[DEFAULT]
base_url = https://example.com
[API]
endpoint = /api/v1
timeout = 30
""")
print(config["API"]["endpoint"]) # /api/v1
print(config["API"]["timeout"]) # 30
File I/O
from ini import parse_file, write_file
# Read from file
var config = parse_file("config.ini")
# Modify
config["Server"]["port"] = "8080"
# Write back
write_file("config.ini", config)
See examples/file_io_example.mojo for a complete example.
Multiline Values
Indented lines are treated as continuations (Python configparser behavior):
from ini import parse
var config = parse("""
[Database]
connection_string = postgresql://host:5432/db
?sslmode=require
&timeout=10
""")
# Result: connection_string contains all three lines with newlines
print(config["Database"]["connection_string"])
# postgresql://host:5432/db
# ?sslmode=require
# &timeout=10
Important: Lines starting with whitespace are ALWAYS treated as continuations, not as new keys. This matches Python configparser behavior.
Python configparser Compatibility
โ ๏ธ Coming in v0.3.0 - ConfigParser API with type converters planned for future release.
For now, all values are strings. Manual conversion:
from ini import parse
var config = parse("...")
# Manual type conversion
var port = int(config["Server"]["port"]) # Int
var debug = config["Server"]["debug"] == "true" # Bool
var timeout = float64(config["API"]["timeout"]) # Float64
Supported INI Features
Classic INI (Default)
[section]headerskey = valuepairs# commentsand; comments- Multiline values (indented continuation)
- Inline comments
Extended (configparser mode)
[DEFAULT]section for shared values- Value interpolation:
%(var)sreferences - Type conversion helpers (getint, getboolean, etc.)
- Case-insensitive section/key names (optional)
Known Limitations
Indented Keys Not Supported
By design, keys with leading whitespace are treated as multiline value continuations:
# โ This does NOT create a key named "indented_key"
[Section]
key1 = value1
indented_key = value2 # This becomes part of key1's value!
This matches Python configparser behavior. If you need indented keys, consider:
- TOML: Native support for nested tables (mojo-toml)
- YAML: Indentation-based structure
- Remove indentation: Keep all keys at column 0
Tab-Indented Keys (Git Config Style)
Git config files use tabs before keys, which mojo-ini treats as continuations. To use Git configs:
# Convert tabs to standard format
sed 's/^\t//' .git/config > config.ini
Or manually remove leading tabs from keys.
Python Compatibility
mojo-ini aims for high compatibility with Python's configparser:
| Feature | Python configparser | mojo-ini v0.2 |
|---|---|---|
| Basic key=value | โ | โ |
| [Sections] | โ | โ |
| [DEFAULT] | โ | ๐ง Planned |
| Multiline values | โ | โ |
| Inline comments | โ | โ |
| Value interpolation | โ | ๐ง Planned |
| Type converters | โ | |
| Case insensitive | โ | ๐ง Planned |
Development
Setup
# Install pixi (if not already installed)
curl -fsSL https://pixi.sh/install.sh | bash
# Install dependencies
pixi install
# Verify Mojo version
pixi run mojo-version
Testing
# Run all tests
pixi run test-all
# Run individual test suites
pixi run test-lexer
pixi run test-parser
pixi run test-writer
pixi run test-configparser
# Build package
pixi run build-package
Benchmarks
# Benchmark mojo-ini performance
pixi run benchmark-mojo
# Compare with Python configparser
pixi run benchmark-python
Roadmap
See ROADMAP.md for detailed development timeline.
v0.2.0 (Released: 2026-01-13) โ
- โ Basic INI parsing (sections, key=value)
- โ INI writer
- โ Comments support (# and ;)
- โ Multiline values
- โ Comprehensive test suite (46 tests)
- โ Performance benchmarks with statistical reporting
- โ File I/O helpers (parse_file, write_file)
v0.3.0 (Target: Q2 2026)
- ๐ง [DEFAULT] section support
- ๐ง Value interpolation %(var)s
- ๐ง configparser API compatibility
- ๐ง Type converters (getint, getboolean, etc.)
v0.4.0 (Target: Q3 2026)
- ๐ง Case-insensitive mode
- ๐ง Git config format support
- ๐ง Advanced interpolation
Documentation
- CHANGELOG.md - Version history and changes
- docs/planning/ - Technical documentation and design docs
- examples/ - Usage examples
Related Projects
- mojo-toml - TOML 1.0 parser/writer for modern configs
- mojo-dotenv - Environment variable management
Together these provide comprehensive configuration file support for Mojo! ๐ฏ
Contributing
Contributions welcome! Please:
- Follow existing code style (see mojo-toml for reference)
- Add tests for new features
- Update documentation
- Use Australian English for docs, US spelling for code
License
Apache 2.0 License - see LICENSE file for details
Made with ๐ฅ by DataBooth