Package: python-ini
A Python INI File Parser and WriterThe INI File ParserThis INI file parser is simple and easy to use and yet
it retains most of the stable and varying features
of thisWikiPedia article.
The ini file syntax is very liberalallows semicolon(;) and hash(#) for comment charactersallows equals(=), colon(:) and space for key/value delimitersallows comma(,) and space as value delimiters in multi-value modeallows number, boolean and string valuesallows unquoted, single-quoted and double-quoted stringsallows escaped characters in strings for:special characterscontrol charactershexadecimal values16-bit Unicode characters32-bit Unicode charactersIt supports both a single-value and multi-value mode,
allowing keys to have only one or a list of multiple values.
Its chief ommission is that it does not directly support subsections.
However, since the period is a valid section name character, section names
such as [A], [A.B] and [A.B.C] are unique section names and could be used to simulate
subsections.Implemented with a single class and five member "getter" functions, it is easy to use
with a short learning curve. For example, this simple progrm would print all values
for all sections and keys in the file INI_FILE_NAME.frompython_ini.ini_fileimportIniFileini=IniFile()# default is single-value modeini.parse(INI_FILE_NAME)if(ini.errors):print('INI FILE ERRORS')print(ini.display_errors())# display any errors found in the INI filekeys=ini.get_keys()# get a list of all keys in the global sectionforkeyinkeys:values=ini.get_values(key)# get the value for each keyprint(key,end=': ')print(values)sections=ini.get_sections()# get a list of all section namesforsectioninsections:keys=ini.get_section_keys(section)# get a list of all keys in each sectionforkeyinkeys:values=ini.get_section_values(section,key)# get the value for each section keyprint('['+section+']:'+key,end=' ')print(values)The INI File WriterThe writer is implemented with a simple three functions to write:comment lineskey/value linessection name linesFor overriding the default values there are three functions for setting some options:delimiterscomment delimiters semicolon(;) or hash(#)key/value delimiters equals(=), colon(:) or spacevalue list delimiters comma(,) or spacebooleansTrue: true, yes, on (all case insensitive)False: false, no, off (all case insensitive)None: none, null, void (all case insensitive)the comment tab - key and section lines may have an optional comment
which is tabbed on the same line. If the line is longer than the tab column
the comment is tabbed on the following line.The following simple program:frompython_ini.ini_writerimportIniWriterw=IniWriter()# set all configurable valuesw.delimiters('#',':',',')w.booleans('TRUE','OFF','void')w.comment_tab(30)# global keysw.comment()w.comment('global keys')w.key('Unicode','a\U0010ffffb','max Unicode character')w.key('flags',[True,False,None],'all "booleans"')# section keysw.comment()w.comment('first section')w.section('__SECTION__','this is a section')w.key('section_key',[1,2,3])w.key('long-value',['abc\xffdef\ue000ghi\U0010ffffjkl'],'hex and Unicode string characters')# print the formatted INI filew.write('output.ini')would write the following INI file to 'output.ini'.# global keys
Unicode: 'a\U0010ffffb'       # max Unicode character
flags: TRUE, OFF, void        # all "booleans"

# first section
[__SECTION__]                 # this is a section
section_key: 1, 2, 3
long-value: 'abc\xffdef\ue000ghi\U0010ffffjkl'
                              # hex and Unicode string charactersInstallationThe Python INI file parser and writer can be installed from eitherGithuborPyPIQuick start guides:GitHub INI parserGitHub INI writerPyPI INI parserPyPI INI writerDocumentationThe full documentation is in the code and in additional documentation files.
It can be generated
withdoxygenfrom the GitHub installation. For example, using the GitHub zip download
and the Ubuntu Linux command line:unzippython-ini-main.zipcdpython-ini-main
sudoaptinstallgraphviz
sudoaptinstalldoxygen
doxygenThe documentation home page will now be found inhtml/index.html.
Or you can view it directly from theAPG website