MojoINI is a simple, lightweight INI file parser written in Mojo. It allows you to read and process INI configuration files with support for sections and key-value pairs.
- Parse INI files with or without sections
- Handles comments and empty lines
- Simple API for reading configuration values
- Written in Mojo for performance and simplicity
Following are the results of running a test involving MojoINI and python's configparser parsing the file 'monster.ini' with 5000 sections and 20keys per section (100,000 keys)
src/mojoini/ # Main package
__init__.mojo # INIParser and main logic
lines.mojo # INI parsing helpers
SDict.mojo # Simple dictionary wrapper
test/ # Test suite
test_parser.mojo # Basic tests for the parser
samples/ # Sample INI files for testing
sample1.ini
sample2.ini
Simple INI (sample1.ini):
name="John Doe"
msg="Hello World!"INI with Section (sample2.ini):
special_number=0
[section1]
field1="some key"
field2="a serious value!"from mojoini import INIParser
var parser = INIParser()
var parsed = parser.read_file("./samples/sample1.ini")
print(parsed.getItem('name')['value']) # Output: John Doe
print(parsed.getItem('msg')['value']) # Output: Hello World!var parser = INIParser()
var parsed = parser.read_file("./samples/sample2.ini")
var section1 = parsed.getItem('section1')
print(section1['field1']) # Output: some key
print(section1['field2']) # Output: a serious value!INIParser()— Create a new parser instance.read_file(file: String) -> Section— Parse an INI file and return aSection(dictionary-like object).parse_contents(contents: String) -> Section- Parse an ini string
.getItem(key: String)— Retrieve a section or value by key..setItem(key: String, value: Dict[String, String])— Set a section or value.
- Lines starting with
;are treated as comments. - Empty lines separate sections.
- Section headers are written as
[section_name]. - Key-value pairs are written as
key=value. - Values can be quoted (e.g.,
key="value").
To run the test suite:
(MojoINI/src) ~ mojo test MIT License

