Skip to main content
Help the Python Software Foundation raise $60,000 USD by December 31st!  Building the PSF Q4 Fundraiser

Binder is a lightweight mapping engine for SQL databases.

Project description

# Binder - A Python SQL Mapper.

Binder is a lightweight SQL mapper for Python that lets you perform SQL operations using native Python data types and methods:

>>>, AND(Trades.q.symbol=='RHAT', Trades.q.trans=='BUY'))
[{'date':, 1, 5), 'symbol': u'RHAT', 'trans': u'BUY', 'price'
: 35.0, 'qty': 100}]

A database row is mapped to a Python dictionary containing native Python data types. Binder gives you control of what SQL query is executed, while taking care of query generation, parameter passing and data conversion.

Currently, Binder supports the SQLite (via Python’s built-in sqlite3 module), PostgreSQL (via psycopg2) and MySQL (via the MySQLdb python module).

See manual.txt for full documentation.

## Installing

Install using pip:

pip install binder

Install from source:

python install

## Quick Tour

Define the schema for a table:

>>> from binder import *
>>> Trades = Table("trades",
...     DateCol("date"), UnicodeCol("trans", 4), UnicodeCol("symbol", 4),
...     IntCol("qty"), FloatCol("price")
... )

Creating a new database using SQLite and create the table we defined above:

>>> conn = SqliteConnection("readme.db3")
>>> conn.create_table(Trades)

Insert a row using a regular Python dictionary:

>>> from datetime import date
>>> row = {
...     "date":date(2006, 1, 5), "trans":"BUY", "symbol":"RHAT",
...     "qty":100, "price":35
... }
>>> conn.insert(Trades, row)
>>> conn.commit()

Finally, retrieve the data:

[{'date':, 1, 5), 'symbol': u'RHAT', 'trans': u'BUY', 'price'
: 35.0, 'qty': 100}]

Project details

Download files

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

Files for binder, version 0.6
Filename, size File type Python version Upload date Hashes
Filename, size binder-0.6.tar.gz (8.3 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page