Skip to main content

Native MonetDB client Python API

Project description

Introduction

pymonetdb is a native python client API for monetDB. This API is cross-platform, and doesn’t depend on any monetdb libraries. It has support for python 2.5+, including Python 3 and PyPy and is Python DBAPI 2.0 compatible.

This is a fork of the original python-monetdb API. python-monetdb is bundled with the MonetDB software suite, but the release cycle is too long to fix small issues. Also I prefer working in github which also enables the use of travis-ci.

https://travis-ci.org/gijzelaerr/pymonetdb.svg?branch=master

Installation

To install the MonetDB python API run the following command from the python source directory:

# python setup.py install

That’s all, now you are ready to start using the API.

Documentation

The python code is well documented, so if you need to find documentation you should have a look at the source code. Below is an interactive example on how to use the monetdb SQL API which should get you started quite fast.

Running the test suite

Install tox and run tox in the root.

You can control the testing behavior using environment variables:

* MAPIPORT - what port is MonetDB running? _50000_ by default
* TSTHOSTNAME -  where is MonetDB running? _localhost_ by default
* TSTPASSPHRASE - what passphrase to test control command? _testdb_ by default
* TSTDB -  what database to use for testing? _demo_ by default
* TSTUSERNAME - username, _monetdb_ by default
* TSTPASSWORD - password, _monetdb_ by default

Note that you first need to create and start a monetdb database. If you want to run the control tests you need to set a passphrase and enable remote control:

$ monetdb create demo
$ monetdb release demo
$ monetdbd set control=yes <path to dbfarm>
$ monetdbd set passphrase=testdb <path to dbfarm>

Examples

examples usage below:

> # import the SQL module
> import pymonetdb
>
> # set up a connection. arguments below are the defaults
> connection = pymonetdb.connect(username="monetdb", password="monetdb",
>                                    hostname="localhost", database="demo")
>
> # create a cursor
> cursor = connection.cursor()
>
> # increase the rows fetched to increase performance (optional)
> cursor.arraysize = 100
>
> # execute a query (return the number of rows to fetch)
> cursor.execute('SELECT * FROM tables')
26
>
> # fetch only one row
> cursor.fetchone()
[1062, 'schemas', 1061, None, 0, True, 0, 0]
>
> # fetch the remaining rows
> cursor.fetchall()
[[1067, 'types', 1061, None, 0, True, 0, 0],
 [1076, 'functions', 1061, None, 0, True, 0, 0],
 [1085, 'args', 1061, None, 0, True, 0, 0],
 [1093, 'sequences', 1061, None, 0, True, 0, 0],
 [1103, 'dependencies', 1061, None, 0, True, 0, 0],
 [1107, 'connections', 1061, None, 0, True, 0, 0],
 [1116, '_tables', 1061, None, 0, True, 0, 0],
 ...
 [4141, 'user_role', 1061, None, 0, True, 0, 0],
 [4144, 'auths', 1061, None, 0, True, 0, 0],
 [4148, 'privileges', 1061, None, 0, True, 0, 0]]
>
> # Show the table meta data
> cursor.description
[('id', 'int', 4, 4, None, None, None),
 ('name', 'varchar', 12, 12, None, None, None),
 ('schema_id', 'int', 4, 4, None, None, None),
 ('query', 'varchar', 168, 168, None, None, None),
 ('type', 'smallint', 1, 1, None, None, None),
 ('system', 'boolean', 5, 5, None, None, None),
 ('commit_action', 'smallint', 1, 1, None, None, None),
 ('temporary', 'tinyint', 1, 1, None, None, None)]

If you would like to communicate with the database at a lower level you can use the MAPI library:

> from pymonetdb import mapi
> server = mapi.Server()
> server.connect(hostname="localhost", port=50000, username="monetdb",
                 password="monetdb", database="demo", language="sql")
> server.cmd("sSELECT * FROM tables;")
...

Project details


Download files

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

Source Distribution

pymonetdb-0.1.1.tar.gz (37.1 kB view details)

Uploaded Source

Built Distributions

pymonetdb-0.1.1-py3.4.egg (66.1 kB view details)

Uploaded Source

pymonetdb-0.1.1-py2.7.egg (64.8 kB view details)

Uploaded Source

pymonetdb-0.1.1-py2.6.egg (65.1 kB view details)

Uploaded Source

File details

Details for the file pymonetdb-0.1.1.tar.gz.

File metadata

  • Download URL: pymonetdb-0.1.1.tar.gz
  • Upload date:
  • Size: 37.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for pymonetdb-0.1.1.tar.gz
Algorithm Hash digest
SHA256 3ae3269b04f2637da341bbda0a4d43dd16c004d627b490c7d3833b29a8a625b3
MD5 c7a085e3631f416d66c8c3dcf2bdef12
BLAKE2b-256 982d06174300a2dec2fc805683e1692dcf8b4315c93fba1a7620848c2f078f0e

See more details on using hashes here.

File details

Details for the file pymonetdb-0.1.1-py3.4.egg.

File metadata

File hashes

Hashes for pymonetdb-0.1.1-py3.4.egg
Algorithm Hash digest
SHA256 cba49485030f58451df3ab04203e522a6817c26341066d45cce00394ebe9bcbe
MD5 d4da8bbedc20f1fd0e2891cfa4d059bd
BLAKE2b-256 d0d55e0ad9da86be396076f91ab88e120363404c9dc1e6cf1ac89bf8fa0856b2

See more details on using hashes here.

File details

Details for the file pymonetdb-0.1.1-py2.7.egg.

File metadata

File hashes

Hashes for pymonetdb-0.1.1-py2.7.egg
Algorithm Hash digest
SHA256 357950f552c5c1c019ef34f7f825564a8b93b4d5d793290bdff280e1b7dd73cd
MD5 b5e9fc88ad8e4ae94e33c5ee2d51a3de
BLAKE2b-256 e394228d7f5434fb7c36a664defee0c0bc11d9051c547b689e6282aaee6e8f92

See more details on using hashes here.

File details

Details for the file pymonetdb-0.1.1-py2.6.egg.

File metadata

File hashes

Hashes for pymonetdb-0.1.1-py2.6.egg
Algorithm Hash digest
SHA256 37e38158394fdba75eea0a8b49e782b2bbdbc14b9637a144cbdf2ce658cd6500
MD5 dcc96dcdc51ffab2e0c172fb8457b283
BLAKE2b-256 c7bfc40c35cc47e8bba2343e62a21c8db19c05a10403818fc2377920599affdf

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page