Skip to main content

Provides resources to handle OpenXML documents.

Project description

openxmllib

openxmllib is a set of tools that deals with the new ECMA 376 office file formats known as OpenXML.

http://www.ecma-international.org/publications/standards/Ecma-376.htm

OpenXML format is actually used by Microsoft Office 2007. Apple iWork’08 and OpenOffice 2.2 have filters to use this format too.

Features

Tested features

  • Extract words from a document for indexing purpose.

  • Get metadata from a document

Planned features

  • Transform a document to HTML

Public API

These examples say all:

>>> import openxmllib
>>> doc = openxmllib.openXmlDocument('office.docx')
>>> # Raises a ValueError on not supported office files.
>>> doc.mimeType
'application/vnd.openxmlformats-officedocument.wordprocessingml.document'
>>> doc.coreProperties # Keys may depend on application
{'title': u'blah...', u'creator': u'John Doe', ...}
>>> doc.extendedProperties # Keys may depend on application
{'Words': u'312', 'Application': u'Your favorite word processor', ...}
>>> doc.customProperties # May return an empty mapping
{'My property': u'My value', ...}
>>> doc.allProperties # Merges core+extended+custom properties (see above)
{...}
>>> doc.indexableText(include_properties=False)
u'all the words of that document body'
>>> doc.indexableText(include_properties=True)
u'all the words of that document body and all properties values'

Note that if you’re not running a Python application, you may get the indexable text from a document with the openxmlinfo.py console utility. Just type:

$ openxmlinfo.py --help

Copying and License

Copyright (c) 2008 Gilles Lenfant

This software is subject to the provisions of the GNU General Public License, Version 2.0 (GPL). A copy of the GPL should accompany this distribution. THIS SOFTWARE IS PROVIDED “AS IS” AND ANY AND ALL EXPRESS OR IMPLIED WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE

More details in the COPYING file included in this package.

Status

This software is in production quality, has been tested on Mac OSX, Linux and Windows with Python 2.4, Python 2.5, lxml 1.3.6 and lxml 2.2.

It should work on other platforms, with Python 2.6, perhaps with other versions of lxml.

Installation

Using the usual setuptools command:

$ [sudo] easy_install openxmllib

Note that this will install the excellent lxml egg too if not already done.

From now you can “import openxmllib” in your Python apps and use the “openxmlinfo.py” command line utility.

Gotchas

Be aware that most text data coming from the various openxmllib services might be us-ascii or Unicode. This is a side effect of lxml (bug or feature ?). It’s up to your application to convert these texts to the appropriate charset.

We do not actually handle exceptions due to malformed XML or various unexpected structures. You should handle the various (potential) problems in a try (…) except (…) block in your application.

Developing and testing

You should grab openxmllib with your subversion client from its repository at Google code.

Then:

$ cd /where/you/installed/openxmllib
$ python setup.py develop

Note that testing does not require the installation:

$ cd tests
$ python runalltests.py

Support

Use the issue tracker provided from the project site.

Credits

  • Gilles Lenfant <gilles dot lenfant at gmail dot com>

  • Kevin Deldycke <kev at coolcavemen dot com>

  • Hugo Lopes Tavares <hltbra at gmail dot com>

Future features and bugfixes

Features

API change

Change API of document constructor such the document source type should be explicite. Examples :

>>> doc = openXmlDocument(url='http://some.site.tld/gossips.docx')
>>> data = open('gossips.docx', 'rb').read()
>>> doc = openXmlDocument(data=data, mime_type='application/xxx')
>>> doc = openXmlDocument(filepath='/somewhere/gossips.docx')
>>> handle = open('/somewhere/gossips.docx')
>>> doc = openXmlDocument(stream=handle)

Remove downloaded temporary file

When data is coming from HTTP (…) URL, it’s stored in a temporary file that’s not deleted after processing.

Support for standard mimetypes module

Add our mime types to standard Python module.

Support for URLs

>>> from openxmllib import openXmlDocument
>>> doc = openXmlDocument('http://www.mydomain.com/mydoc.docx')

Human readable plain text conversion

>>> from openxmllib import openXmlDocument
>>> doc = openXmlDocument(...)
>>> doc.textDocument(target_directory)

(this may be not possible for spreadsheets)

HTML conversions

>>> from openxmllib import openXmlDocument
>>> doc = openXmlDocument(...)
>>> doc.htmlDocument(target_directory)

This requires to find open source XSLT stylesheets.

Document generation

FIXME: more to say here

Bugfixes

…Waiting for feedback ;o)

History

1.0.5

  • Optims on large documents. [gilles.lenfant_AT_gmail_DOT_com]

  • CamelCased functions and method names in consistency with applied rules. [gilles.lenfant_AT_gmail_DOT_com]

  • Version reset to 1.0.5 [gilles.lenfant_AT_gmail_DOT_com]

  • Support for urllib compatible URLs [gilles.lenfant_AT_gmail_DOT_com]

  • New: Support for URLs [hltbra_AT_gmail_DOT_com]

  • Fixed implementation to that old tests pass (the “midword”/”metadata” case, bold + normal style was not ok) [hltbra_AT_gmail_DOT_com]

1.0.4

  • Compliance with python 2.5 and lxml 2.2 Still works with python 2.4 and lxml 1.3.6 [gilles.lenfant_AT_gmail_DOT_com]

  • Automate package and version definition

  • Bump version to 1.0.4 2008-12-11 [kev_AT_coolcavemen_DOT_com]

1.0.3

  • Conforming XPath constructor signature. [gilles.lenfant_AT_gmail_DOT_com]

  • New test files built with Mac Office 2008 [gilles.lenfant_AT_gmail_DOT_com]

1.0.2

  • Fix bad “egging”. [kev_AT_coolcavemen_DOT_com]

1.0.1

  • Egg-ification. [kev_AT_coolcavemen_DOT_com]

1.0.0

  • First public version. [gilles.lenfant_AT_gmail_DOT_com]

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

openxmllib-1.0.5.tar.gz (65.3 kB view hashes)

Uploaded Source

Built Distribution

openxmllib-1.0.5-py2.4.egg (26.2 kB view hashes)

Uploaded Source

Supported by

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