Dameng Database Python Interface

2.5.32 · active · verified Thu Apr 16

dmPython is the official Python interface to the Dameng database, designed to facilitate connections and operations following the Python DB API 2.0 specification. It enables Python applications to directly interact with Dameng databases. The library is actively maintained by Dameng Database and currently stands at version 2.5.32, with frequent updates addressing bug fixes and new features.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to establish a connection to a Dameng database, execute a simple query, fetch the result, and properly close the cursor and connection. Ensure you replace the placeholder connection details with your actual database credentials.

import dmPython
import os

# Replace with your actual Dameng database connection details
user = os.environ.get('DM_USER', 'SYSDBA')
password = os.environ.get('DM_PASSWORD', 'Dameng123')
host = os.environ.get('DM_HOST', 'localhost')
port = os.environ.get('DM_PORT', '5236')
schema = os.environ.get('DM_SCHEMA', 'SCH1')

connection_string = f'{user}/{password}@{host}:{port}/{schema}'

try:
    conn = dmPython.connect(connection_string)
    cursor = conn.cursor()

    cursor.execute("SELECT SYSDATE FROM DUAL")
    result = cursor.fetchone()
    print(f"Current database time: {result[0]}")

    cursor.close()
    conn.close()
except dmPython.DatabaseError as e:
    print(f"Database connection or query error: {e}")

view raw JSON →