Introduction to ODFPY
Odfpy is a library to read and write OpenDocument v. 1.1 files. The main focus has been to prevent the programmer from creating invalid documents. It has checks that raise an exception if the programmer adds an invalid element, adds an attribute unknown to the grammar, forgets to add a required attribute or adds text to an element that doesn't allow it.
These checks and the API itself were generated from the RelaxNG schema, and then hand-edited. Therefore the API is complete and can handle all ODF constructions, but could be improved in its understanding of data types.
Take a look at the api-for-odfpy.odt manual. Most of the manual is generated from the RelaxNG schema.
In addition to the API, there are a few scripts:
- csv2odf - Create OpenDocument spreadsheet from comma separated values
- mailodf - Email ODF file as HTML archive
- odf2xhtml - Convert ODF to (X)HTML
- odf2xml - Create OpenDocument XML file from OD? package
- odf2mht - Convert ODF to HTML archive
- odfimgimport - Import external images
- odflint - Check ODF file for problems
- odfmeta - List or change the metadata of an ODF file
- odfoutline - Show outline of OpenDocument
- odfuserfield - List or change the user-field declarations in an ODF file
- xml2odf - Create OD? package from OpenDocument in XML form
Take also a look at the contrib folder.
Getting the package
- You can download from the OSOR forge.
- You can use the Python package index
-
You can grab the odfpy project source code with this command:
svn export https://svn.forge.osor.eu/svn/odfpy/trunk odfpy
Older versions
The project was originally hosted at OpenDocument Fellowship, but this is now the correct location.
Example: Hello world
from odf.opendocument import OpenDocumentText
from odf.text import P
textdoc = OpenDocumentText()
p = P(text="Hello World!")
textdoc.text.addElement(p)
textdoc.save("helloworld", True)
Why isn't it called PyODF?
It could have been, and it was a close call, but at the time I was influenced by the libraries xmpppy, jabberpy and odfphp. It was only later I realised there is a growing convention to call packages python-something or PySomething due to Linux package naming. Feel free to call it python-odf.