Skip to main content

This version of the Python 3 MonetDB client includes some additional features to support bulk copy operations

Introduction

This is the new native Python client API. This API is cross-platform, and doesn’t depend on any monetdb libraries. It has support for Python 3.2+ and is Python DBAPI 2.0 compatible.

This is a fork of the code distributed with MonetDB that adds support for asynchronous operation (requires greenlet) and bulk I/O with COPY.

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.

Examples

There are some examples in the ‘examples’ folder, but here are is a line by line example of the SQL API:

> # import the SQL module
> import monetdb.sql
>
> # set up a connection. arguments below are the defaults
> connection = monetdb.sql.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 monetdb import mapi
> server = mapi.Server()
> server.connect(hostname="localhost", port=50000, username="monetdb", password="monetdb", database="demo", language="sql")
> server.cmd("sSELECT * FROM tables;")
...

Copying a table from PostgreSQL (using the Psycopg2 driver) to MonetDB:

data = io.StringIO()

pg_cursor = pg_conn.cursor()
pg_cursor.copy_expert(
    """COPY {} TO STDOUT WITH CSV QUOTE '"' ESCAPE '\\' NULL ''""".format(pg_table), data)
data.seek(0)

monetdb_cursor = monetdb_conn.cursor()
monetdb_cursor.copy_from(data, monetdb_table, string_quote='"', null_string='')
monetdb_conn.commit()

Metadata

Release files for dw-python-monetdb-async 11.19.9

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for dw-python-monetdb-async 11.19.9
File Size Uploaded
dw-python-monetdb-async-11.19.9.tar.gz 22.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for dw-python-monetdb-async 11.19.9
File Interpreter ABI Platform
dw_python_monetdb_async-11.19.9-py3-none-any.whl Python 3 none any Details

Total release size: 48.7 kB

Release files / dw-python-monetdb-async-11.19.9.tar.gz

Download URL dw-python-monetdb-async-11.19.9.tar.gz
Size 22.3 kB
Tags Source
SHA-256 checksum
How to use checksums
71799bc59ae3dace637bcfd27212c228bcd50ee3afc5e8647c4fb82e5f55cd5a
BLAKE2b-256 checksum
How to use checksums
97a7d843d5876a178f3f74d3af9d5b83cec0545fadce25eff9081627728f8a7d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / dw_python_monetdb_async-11.19.9-py3-none-any.whl

Download URL dw_python_monetdb_async-11.19.9-py3-none-any.whl
Size 26.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
04bce94f57514b088a8338f0d5ecd2e8dd10ac1185434b142f97e1bb10b93797
BLAKE2b-256 checksum
How to use checksums
9ad4b7656316c2b6e44d7b1284a742b0843f039cad3aa686758ac3f643877037
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

12.0.2

1 release file

12.0.1

2 release files

This release

11.19.9 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page