This is a pre-production deployment of Warehouse, however changes made here WILL affect the production instance of PyPI.
Latest Version Dependencies status unknown Test status unknown Test coverage unknown
Project Description

Introduction

Any2csv is a helper module to ease producing CSV files from different sources. It is mainly usefull to consume SQLAlchemy requests results or any other ORM that produces objects.

Licence

This package is covered by the permissive BSD licence.

Python versions

Any2csv is tested with the help of tox on python 2.7 and python 3.4 It may work with older versions (some parts were developped using python 2.3) but no tests or even garantee is made on this.

Example Usage

from any2csv import Any2CSV


class SubObj(object):
        def __init__(self, v):
                self.field1 = v
                self.field2 = "%s%s" % ("field2", v)


class MyObj(object):
        def __init__(self, v):
                self.field1 = v
                self.field2 = "%s%s" % ("field2", v)
                self.subobj = SubObj(v)

vals = ['a', 'b', 'c']
objlist = [MyObj(val) for val in vals]

writer = Any2CSV(
        target_filename='testoutput1.csv',
        column_mappings=[
                {'attr': 'field1', 'colname': 'field 1'},
                {'attr': 'field2', 'colname': 'field 2'},
                {'attr': 'subobj.field1', 'colname': 'field 1 of subobj'},
                {'attr': 'subobj.field2', 'colname': 'field 2 of subobj'},
        ]
)

writer.write(objlist)

In this example we use a simple in-memory list with dummy objects but the Any2CSV adapter works with any iterator as long as it outputs objects and you are able to describle the source attr and the desired colname.

If you want to apply rendering functions to your column you need to add a renderer definition to the column_mappings, here is how to do it:

import logging
from any2csv import Any2CSV


class SubObj(object):
        def __init__(self, v):
                self.field1 = v
                self.field2 = "%s_%s" % ("field2", v)


class MyObj(object):
        def __init__(self, v):
                self.field1 = v
                self.field2 = "%s_%s" % ("field2", v)
                self.subobj = SubObj(v)


def render_split(value=None):
        if value is None:
                v = u''
        else:
                v = value

        return v.split('_')[1]

logging.basicConfig()
vals = ['a', 'b', 'c']
objlist = [MyObj(val) for val in vals]

writer = Any2CSV(
        'testoutput2.csv',
        [
                {'attr': 'field1', 'colname': 'field 1'},
                {'attr': 'field2', 'colname': 'field 2', 'renderer': render_split},
                {'attr': 'subobj.field1', 'colname': 'field 1 of subobj'},
                {'attr': 'subobj.field2', 'colname': 'field 2 of subobj'},
        ],
        show_first_line=True,
)

writer.write(objlist)

Changelog

0.3.4 Nov. 5 2015

  • Fixed unicode support in Python2 (and reworked it in Python3)
  • Added possibility to pass iterables of dictionaries (as opposed to only instances) to the writer. For the moment the passed dict must have keys that match to target output columns, but we may add support for columns remapping in the future.

0.3.3 Jul. 29 2015

  • Now based on any2 for the base tools
  • Fully test covered
  • All raised exceptions now are based on Any2Error to help users catch them

Contributors

By order of contribution date:

Release History

Release History

0.3.5

This version

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.3.4

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.3.3

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.3.2

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.3.2.dev1

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

Download Files

Download Files

TODO: Brief introduction on what you do with files - including link to relevant help section.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
any2csv-0.3.5-py2.7.egg (7.2 kB) Copy SHA256 Checksum SHA256 2.7 Egg Apr 25, 2016
any2csv-0.3.5-py2-none-any.whl (5.0 kB) Copy SHA256 Checksum SHA256 2.7 Wheel Apr 25, 2016
any2csv-0.3.5.tar.gz (6.5 kB) Copy SHA256 Checksum SHA256 Source Apr 25, 2016
any2csv-0.3.5.zip (9.6 kB) Copy SHA256 Checksum SHA256 Source Apr 25, 2016

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS HPE HPE Development Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting