Skip to main content

Python library for OpenDocument Format

Project description

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.

  • 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

uv run pytest

The tests should run for a few minutes and issue no error.

The full test suite uses tox to check different Python and lxml versions.

A special effort is made to limit the dependencies of this library: the only dependency (outside development) is lxml. The lxml versions depend mainly on the version of Python used, see the pyproject.toml file for details.

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_table(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 two .odt document.
  • odfdo-folder: convert standard ODF file to folder and files, and reverse.
  • odfdo-headers: print the headers of an ODF file.
  • odfdo-highlight: highlight the text matching a pattern (regex) in an ODF file.
  • odfdo-markdown: export text document in Markdown format to stdout.
  • odfdo-replace: find a pattern (regex) in an ODF file and replace by some string.
  • odfdo-show: dump text from an ODF file to the standard output, and optionally styles and meta informations.
  • odfdo-styles: command line interface tool to manipulate styles of ODF files.
  • odfdo-table-shrink: shrink tables to optimize width and height.
  • odfdo-userfield: show or set the user-field content in an ODF file.

tl;dr

'Intended Audience :: Developers'

Documentation

There is no detailed documentation or tutorial, but:

  • the recipes folder contains more than 60 working sample scripts,
  • the doc folder contains an API reference documentation (auto generated), including recipes.

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

I you work on .ods files (spreadsheet), you may be interested by these scripts using this library to parse/generate .ods files: 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, see: https://github.com/lpod/lpod-python

odfdo is an adaptation of this former project to Python 3.x with several improvements.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

odfdo-3.14.6.tar.gz (4.3 MB view details)

Uploaded Source

Built Distribution

odfdo-3.14.6-py3-none-any.whl (257.6 kB view details)

Uploaded Python 3

File details

Details for the file odfdo-3.14.6.tar.gz.

File metadata

  • Download URL: odfdo-3.14.6.tar.gz
  • Upload date:
  • Size: 4.3 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.3

File hashes

Hashes for odfdo-3.14.6.tar.gz
Algorithm Hash digest
SHA256 138b6867caa0146e498745eba44b418e36b57def513c5b8865c855c07ff248b0
MD5 e43352664dcd1dec9fdd1b558df74499
BLAKE2b-256 8def0595e6f728c64687399cede3f7045ae6b74454366dcbedc05e1291dbc1a4

See more details on using hashes here.

File details

Details for the file odfdo-3.14.6-py3-none-any.whl.

File metadata

  • Download URL: odfdo-3.14.6-py3-none-any.whl
  • Upload date:
  • Size: 257.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.3

File hashes

Hashes for odfdo-3.14.6-py3-none-any.whl
Algorithm Hash digest
SHA256 5a7cd744e0502d6fb3af79dc654bea7482c9173071e3b43d3caeda983bafec94
MD5 b6d7c0e8f36c6d49e00065d9f9ff4a51
BLAKE2b-256 f2e3d978194db1d5f697ea04c8c98dc329334703bc6ffc82cce49ac7c71cdfde

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page