Registry / database / pymonetdb

pymonetdb

JSON →
library1.9.0pypypi✓ verified 85d ago

pymonetdb is the native Python client API for MonetDB. It is cross-platform and does not depend on any MonetDB libraries. It supports Python 3.7+ and PyPy, and is Python DBAPI 2.0 compatible. Besides standard DBAPI 2.0 functionality, it also provides MonetDB-specific features like file transfers. It is currently at version 1.9.0 and has an active development and release cadence.

pip install pymonetdb
INSTALL
IMPORT
SIG · PYMONETDB
P
pymonetdb
databasepythonv1.9.0
Install
1.6s avg
Import
201ms
Disk
17MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.9.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.920 runs
installs and imports cleanly · install 0.0s · import 0.216s · 18.7MB
glibc
py 3.103.920 runs
installs and imports cleanly · install 1.6s · import 0.187s · 19MB
17MB installed
● package 17MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Connection
from pymonetdb import Connection
import pymonetdb
connect
from pymonetdb import connect
import pymonetdb
DatabaseError
from pymonetdb import DatabaseError
import pymonetdb

This quickstart demonstrates how to establish a connection to a MonetDB database, execute a simple SQL query, and fetch results using `pymonetdb.connect()` and cursor operations. It emphasizes using environment variables for sensitive connection parameters and proper error handling with connection closure.

import pymonetdb import os # Configure connection details using environment variables for security hostname = os.environ.get('MONETDB_HOSTNAME', 'localhost') port = int(os.environ.get('MONETDB_PORT', 50000)) username = os.environ.get('MONETDB_USERNAME', 'monetdb') password = os.environ.get('MONETDB_PASSWORD', 'monetdb') database = os.environ.get('MONETDB_DATABASE', 'demo') conn = None try: # Establish a connection to the MonetDB database conn = pymonetdb.connect( hostname=hostname, port=port, username=username, password=password, database=database ) print("Successfully connected to MonetDB!") # Create a cursor object cursor = conn.cursor() # Execute a simple query cursor.execute("SELECT 'Hello from pymonetdb!' AS message;") # Fetch the result result = cursor.fetchone() print(f"Query result: {result[0]}") # Example of fetching multiple rows (e.g., system tables) cursor.execute("SELECT name FROM sys.tables ORDER BY name LIMIT 3;") tables = cursor.fetchall() print("First 3 system tables:", [t[0] for t in tables]) # Always commit changes if any DML operations were performed # conn.commit() except pymonetdb.Error as e: print(f"MonetDB Database error: {e}") except Exception as e: print(f"An unexpected error occurred: {e}") finally: # Ensure the connection is closed if conn: conn.close() print("Connection closed.")
Debug
Known issues
breakingThe `pymonetdb` library is the official and recommended Python client for MonetDB, replacing the older `python-monetdb` module. When migrating, ensure all `import monetdb` statements are updated to `import pymonetdb`.
fix
Replace `import monetdb` with `import pymonetdb`.
affects: <= 1.0 (old `python-monetdb` library)
gotchaClosing a database connection without an explicit `conn.commit()` will automatically trigger an implicit `rollback()` for any pending transactions. Ensure `commit()` is called for desired persistence.
fix
Explicitly call `conn.commit()` before `conn.close()` if changes should be saved.
affects: All versions
gotchaUsing the `COPY INTO ... ON CLIENT` SQL statement for file transfers without proper security measures can lead to critical vulnerabilities. It allows the MonetDB server to request the client to open and transfer local files. Always register a `pymonetdb.SafeDirectoryHandler` to restrict file access to an allowed directory.
fix
Implement `pymonetdb.set_uploader()` and `pymonetdb.set_downloader()` with a `SafeDirectoryHandler` instance configured to a secure, restricted path.
affects: All versions using `COPY INTO ... ON CLIENT`
gotchaFor optimal performance when fetching large result sets, consider adjusting `cursor.arraysize`. The default batch fetching behavior might not be efficient for all workloads, and increasing `arraysize` can reduce network round trips.
fix
Set `cursor.arraysize = N` (where N is the desired number of rows to fetch per batch) after creating the cursor and before fetching results.
affects: All versions
Upgrade
Version history
1.9.0latest on PyPI · released Nov 13, 2025
Audit
Dependencies

No dependency data recorded yet.

Agent activity
10 hits · last 30 days
node
8
OpenAI (training)
1
Resources
pymonetdb — pip install pymonetdb · libregistry