Skip to main content
This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (
Help us improve Python packaging - Donate today!

A library to generate Excel files from Python iterables

Project Description


any2xl is a helper module to ease producing XLS(X) files from different sources. It uses openpyxl by Eric Gazoni to produce the actual XLS file. It provides primitives and helpers alongside with any2 that help produce XLS(X) files from diverse sources.


This package is covered by the permissive BSD licence.

Python versions

any2xl works on python 2.7 and python 3.4

Example Usage

from datetime import datetime as dt
from decimal import Decimal
from any2xl import List2xl

target_filename = "out.xls"

data = [
    (, Decimal("15.3"), u'Noël'),
    (, Decimal("10.3"), u'Pentecôte'),
    (, Decimal("100.02"), u'Jérôme'),
    (, Decimal("0.03"), u'Some unaccented data'),

colnames = ["Time", "Amount", "Description"]

# we want column names as the first line of our XLS file
# so we give the names to the constructor
xl = List2xl(target_filename, colnames=colnames)

# and we ask the write method to write the names
xl.write(data, write_names=True)

# serialize to disk

In this example we only act as a really thin wrapper over the openpyxl library and if you only need this kind of functionality you may be better off using directly openpyxl…

The purpose of any2xl and were it is really interesting is when you have more complex datastructures:

from decimal import Decimal
import datetime

from any2xl import List2xl
from any2 import Obj2List
from any2 import NameTransformer

quantizer = Decimal('0.01')

class SubObj(object):
    def __init__(self, v):
        self.amount = Decimal('42.4242424242')
        self.start_date =, month=2, day=3)
        self.description = "%s_%s" % ("Task", v)

class MyObj(object):
    def __init__(self, v, urgent):
        self.description = v
        self.urgent = urgent
        self.subobj = SubObj(v)

def quantize2(value):
    return value.quantize(quantizer)

def yesno(value):
    if value:
        return "Yes"
        return "No"

vals = [('Project 1', True), ('Project 2', False), ('Project 3', False)]
objs = [MyObj(*val) for val in vals]

# the name transformer will work on output columns
# in fact indexes...
colnames = [
    "Start Date",
    "Task Description",
    "Is Urgent"
transformer = NameTransformer(colnames)
transformer.register_func('Amount', quantize2)
transformer.register_func('Is Urgent', yesno)

# to adapt an object as a list we must give the list of attributes we want
attrs = [
data_feed = Obj2List(objs, attrs, transformer=transformer)

xl = List2xl('obj2list_out.xls', colnames=colnames)
xl.write(data_feed, write_names=True)

Here you see that we have a (somewhat complex) input iterator yielding imbricated objects and we need to transform some of the data during the process.

We could have used other transformers, the list is in any2.transformers


  • Adding unit tests is our main priority, the main functionalities are in any2 which is 100% test covered. So we only need to add the thin wrapper above openpyxl in our unit tests
  • At the moment we can only produce “raw” xls files without formatting. We plan to introduce new xl specific formatters to be able to apply cell and row formattings in the same way we use transformers.


0.1 Jul. 29 2015

  • Initial release


By order of contribution date:

Release History

This version
History Node


History Node


Download Files

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

Filename, Size & Hash SHA256 Hash Help File Type Python Version Upload Date
(4.3 kB) Copy SHA256 Hash SHA256
Egg 3.4 Jul 29, 2015
(3.7 kB) Copy SHA256 Hash SHA256
Wheel 3.4 Jul 29, 2015
(3.9 kB) Copy SHA256 Hash SHA256
Source None Jul 29, 2015
(6.2 kB) Copy SHA256 Hash SHA256
Source None Jul 29, 2015

Supported By

Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Google Google Cloud Servers