Skip to content
Python module for parsing CSV files into sqlite tables, represented as native python objects
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.


Python module for parsing CSV files into sqlite tables, represented as native python objects, e.g.,

>>> import Reports
>>> foo = Reports.Report('foo.csv')
>>> len(foo)
>>> foo.headers
['id', 'price', 'description']
>>> foo.sum('price')
>>> everyother = foo[0:100:2]
>>> len(everyother)

A Reports class provides a collection of reports, and uses the same sqlite connection (to allow joins across reports). In other words, all of the csv reports will be viewed as tables within a single database, and all reports can be accessed by named attributes. E.g.,

>>> reports = Reports.Reports('/path/to/reports')
>>> reports.billing_detail.sum('Tax Amount')
>>> reports.tax_detail.sum('Amount')
>>> taxes = reports.db.execute('SELECT, b.price, t.amount FROM billing_detail b, tax_detail t WHERE t.billing_id =').fetchall()
>>> len(taxes)

Optionally, you can specify a table name and a database connection
-- by default, the table name is extracted from the csv file and a per-instance in-memory sqlite3 connection will be used. In practice you'd only care about these parameters if you want a shared db to do joins against multiple reports

>>> conn = sqlite3.connect(':memory:')
>>> sales_tax = Report('sales-tax.csv', 'sales_tax', conn)
>>> billing_summary = Report('billing-summary.csv', 'billing_summary', conn)
>>> # We should have both tables (sales_tax and billing_summary)
>>> curs = conn.cursor()
>>> curs.execute('SELECT name FROM sqlite_master WHERE type="table"').fetchall()
[(u'sales_tax',), (u'billing_summary',)]
You can’t perform that action at this time.