Skip to main content

odfdo

Release Build Status License PyPI Downloads

OpenDocument Format (ODF, ISO/IEC 26300) library for Python

logo

odfdo is a Python library for programmatically creating, parsing, and editing OpenDocument Format (ODF) files. It provides an interface for interacting with .odt, .ods, .odp, and other ODF file types. The library comes with a set of utilities and recipes for common actions to make it easier to use.

odfdo saves documents as ODF 1.4 and can load documents created with ODF 1.0, 1.1, 1.2, 1.3 or 1.4.

  • Document Creation: Generate new ODF documents.
  • Content Manipulation: Add, modify, or delete text, paragraphs or tables.
  • Table Operations: Create, populate, and modify tables.
  • Style Management: Control formatting through different ways.
  • Drawing and Presentation: Less advanced features, but allow work with elements in .odg and .odp files.
  • Metadata: Read and write document metadata.

Project: https://github.com/jdum/odfdo

Author: jerome.dumonteil@gmail.com

License: Apache License, Version 2.0

odfdo is a derivative work of the former lpod-python project.

Installation

Installation from Pypi (recommended):

pip install odfdo

Installation from sources:

uv sync

After installation from sources, you can check everything is working. The tests should run for a few seconds and issue no error. Test coverage should be close to 100%.

uv sync --dev
uv run pytest -n8

To generate the documentation in the ./docs directory:

uv sync --group doc
uv run python doc_src/generate_doc.py

Dependencies

The project is tested on Python 3.10 to 3.14 (Linux, Mac, Windows). See previous releases for earlier versions of Python. For Python 3.9, see branch support/python39.

A special effort has been made to limit the dependencies of this library: the only (non-development) dependency is lxml. The required versions of lxml depend mainly on the version of Python used; see the pyproject.toml file for details. The project tries to keep up with lxml version updates regularly.

Usage Overview

Creating a "Hello world" Text Document

from odfdo import Document, Paragraph

doc = Document('text')
doc.body.append(Paragraph("Hello world!"))

doc.save("hello.odt")

Modifying a Spreadsheet

from odfdo import Document

doc = Document('existing_spreadsheet.ods')
sheet = doc.body.get_sheet(0)

print(f"Value of A1: {sheet.get_cell('A1').value}")
sheet.set_value('B2', 'Updated Value')

doc.save('modified_spreadsheet.ods')

Utilities

A few scripts are provided with odfdo:

  • odfdo-diff: show a diff between the textual content of two ODT files.
  • odfdo-folder: convert a standard ODF file (zip archive) to a folder structure, or convert a folder structure back to an ODF file.
  • odfdo-flat: convert an ODF file (zip archive or folder) to a flat XML ODF file, or convert a flat ODF XML file back to an ODF zip file.
  • odfdo-headers: display the hierarchical headers (headings) of an ODF text document. The headers are printed with their numbering and can be limited by a specified depth.
  • odfdo-highlight: search for a regular expression pattern in an ODF text document and apply a highlighting style to the matching text. The style can include italic, bold, text color, and background color.
  • odfdo-markdown: convert an ODF text or spreadsheet document to Markdown format and print to standard output.
  • odfdo-replace: find and replace text in an ODF file using a regular expression pattern.
  • odfdo-show: display various parts of an ODF document, including text content, styles, and metadata, to standard output or a specified directory.
  • odfdo-styles: manipulate styles within OpenDocument files: display, delete, or merge them.
  • odfdo-table-shrink: optimize the width and height of tables in an ODF spreadsheet by removing empty trailing rows and columns.
  • odfdo-userfield: inspect and modify user-defined fields within an ODF document.
  • odfdo-from-csv: import data from a CSV file into a new ODS (OpenDocument Spreadsheet) file.
  • odfdo-to-csv: export a table from an ODS (OpenDocument Spreadsheet) file to a CSV file.
  • odfdo-from-json: import data from a JSON file into a new ODS (OpenDocument Spreadsheet) file.
  • odfdo-to-json: export one or all tables from an ODF document to a JSON file.
  • odfdo-meta-print: extract and display the metadata from an ODF file.
  • odfdo-meta-update: update the metadata of an ODF file by merging from a JSON file or stripping to minimal content.

tl;dr

'Intended Audience :: Developers'

Documentation

  • The recipes folder contains over 80 examples of functional scripts, including interoperability recipes for Pandas, Polars, PyExcel, DuckDB, Tabulate, NumPy, and OpenPyXL.
  • The auto-generated documentation exposes public APIs and recipes.

Online documentation: https://jdum.github.io/odfdo

About styles

The best way to apply style is by merging styles from a template document into your generated document (See odfdo-styles script). Styles are a complex matter in ODF, so trying to generate styles programmatically is not recommended. Several recipes provide an example of manipulating styles, including: change_paragraph_styles_methods.py,create_basic_text_styles, add_text_span_styles.

Related project

If you work on .ods files (spreadsheet), you may be interested by these scripts using this library to parse/generate .ods files with style management: https://github.com/jdum/odsgenerator and https://github.com/jdum/odsparsator

Former lpod-python library

lpod-python was written in 2009-2010 as a Python 2.x library. odfdo is an adaptation of this former project to Python 3.x with several improvements.

Metadata

Release files for odfdo 3.26.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for odfdo 3.26.2
File Size Uploaded
odfdo-3.26.2.tar.gz 348.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for odfdo 3.26.2
File Interpreter ABI Platform
odfdo-3.26.2-py3-none-any.whl Python 3 none any Details

Total release size: 804.3 kB

Release files / odfdo-3.26.2.tar.gz

Download URL odfdo-3.26.2.tar.gz
Size 348.6 kB
Tags Source
SHA-256 checksum
How to use checksums
5d1aa82cdf906cc00c2f247c39f117b8a22e791eed9464319d1d3c0185cd1022
BLAKE2b-256 checksum
How to use checksums
24141b91a76e3965536fe5b032dd413222e58ead283a191e54d1a5ab7afd281f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.9

Release files / odfdo-3.26.2-py3-none-any.whl

Download URL odfdo-3.26.2-py3-none-any.whl
Size 455.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
63854acad12ad320b3e09155d4be014845a5a483f749d4346986d76fba4a8bbf
BLAKE2b-256 checksum
How to use checksums
d8c45e6b1c29c9e82fda7d4b723ceba54d08adf31ddf64681d450d7ab72d5e0a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.9

Release history Release notifications | RSS feed

3.26.3

2 release files

This release

3.26.2 This release

2 release files

3.26.1

2 release files

3.26.0

2 release files

3.24.7

2 release files

3.24.6

2 release files

3.24.5

2 release files

3.24.4

2 release files

3.23.1

2 release files

3.23.0

2 release files

3.22.6

2 release files

3.22.5

2 release files

3.22.3

2 release files

3.22.2

2 release files

3.22.1

2 release files

3.21.0

2 release files

3.18.3

2 release files

3.18.2

2 release files

3.17.6

2 release files

3.17.5

2 release files

3.17.2

2 release files

3.17.1

2 release files

3.17.0

2 release files

3.16.7

2 release files

3.16.6

2 release files

3.16.4

2 release files

3.16.3

2 release files

3.16.2

2 release files

3.15.1

2 release files

3.15.0

2 release files

3.14.6

2 release files

3.14.5

2 release files

3.14.4

2 release files

3.14.3

2 release files

3.14.0

2 release files

3.13.9

2 release files

3.13.8

2 release files

3.13.5

2 release files

3.13.4

2 release files

3.13.2

2 release files

3.13.1

2 release files

3.12.1

2 release files

3.12.0

2 release files

3.11.0

2 release files

3.10.1

2 release files

3.10.0

2 release files

3.9.4

2 release files

3.9.3

2 release files

3.9.2

2 release files

3.9.1

2 release files

3.9.0

2 release files

3.8.0

2 release files

3.7.13

2 release files

3.7.12

2 release files

3.7.11

2 release files

3.7.9

2 release files

3.7.8

2 release files

3.7.7

2 release files

3.7.6

2 release files

3.7.5

2 release files

3.7.4

2 release files

3.7.3

2 release files

3.7.2

2 release files

3.7.0

2 release files

3.6.0

2 release files

3.5.1

2 release files

3.5.0

2 release files

3.4.7

2 release files

3.4.6

2 release files

3.4.5

2 release files

3.4.4

2 release files

3.4.3

2 release files

3.4.2

2 release files

3.4.1

2 release files

3.4.0

2 release files

3.3.7

2 release files

3.3.6

2 release files

3.3.5

2 release files

3.3.2

2 release files

3.3.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page