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!

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

    # 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')


For issues and source control, use github:

Release History

This version
History Node


History Node


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.4 kB) Copy SHA256 Hash SHA256
Source None Dec 14, 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 DreamHost DreamHost Log Hosting