This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (pypi.python.org).
Help us improve Python packaging - Donate today!

Mutable record type for dealing with flat files like CSV or pipe-delimited data

Project Description

Mutable record type for dealing with flat files like CSV or pipe delimited data.

Dealing with flat files is painful. Instead, use vinyl to declaratively describe and validate common flat file formats. Vinyl gives you the convenience of attribute-style access like a namedtuple, but in a mutable data type suitable for easily transforming data.

import os
import csv
from vinyl.record import Record
from vinyl.fields import VarCharField, FixedCharField

# declare the data format
class TestRecord(Record):
    customer_name = VarCharField(max_length=50)
    customer_number = FixedCharField(field_length=10, pad_with='0', justify='right' )
    start_time = FixedCharField(value='00:00:00', field_length=8)

# create an instance
record = TestRecord()

# read data from a file
with open(os.path.join(os.path.dirname(__file__), 'example.txt')) as f:
    reader = csv.reader(f)
    # copy a row of CSV data to the recordinstance
    record._load(*reader.next())

    # check the name was read correctly
    assert record.customer_name == 'a customer name with max length=50'

    # set a different customer number
    record.customer_number = '3'

    # number is reformatted according to the field settings
    assert record.customer_number == '0000000003'

    # a static field
    assert record.start_time == '00:00:00'

    print repr(record)
    # >>> TestRecord(customer_name=u'a customer name with max length=50',
    #                customer_number=u'0000000003', start_time=u'00:00:00')

Support

For issues and source control, use github:

https://github.com/mrj0/vinyl/

Release History

Release History

This version
History Node

0.6

History Node

0.5

History Node

0.3

History Node

0.1

Download Files

Download Files

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

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
vinyl-0.6.tar.gz (4.4 kB) Copy SHA256 Checksum SHA256 Source Dec 14, 2015

Supported By

WebFaction WebFaction Technical Writing 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 Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting