Skip to main content

zodbc

This odbc client tries to mirror pyodbc's interface and behavior, while also treating pyarrow compatibility as a first class citizen and providing various performance benefits. At the moment it is only tested with the msodbc driver. Compilation and installation is made easy by ziglang being a simple build dependency. The only system dependencies for compilation should be development headers for unixodbc (if on linux) and python.

Installation

pip install zodbc

On Linux you may also need the driver manager unixodbc as well as the odbc driver for your database, like msodbcsql.

Features

DB API 2

import zodbc
import os

con = zodbc.connect(os.environ["ODBC_CONSTR"])  # Connect with odbc connection string or DSN
cur = con.cursor()  # Cursor, which translates to an odbc statement handle

# python parameters & return values, data types like str, int, bool, UUID, decimal, date, time, datetime
cur.execute("select ? a", [42])
assert cur.fetchone()[0] == 42

# Short hand alternative for getting column names from cur.description
assert [c[0] for c in cur.description] == cur.column_names == ["a"]

con.commit()  # Transactions, autocommit is disabled by default

Fetch methods

  • The DB API 2 fetch methods fetchone, fetchmany and fetchall return (lists of) Rows, which are essentially tuples that also allow named access.
  • fetchtuples returns a list of tuples. Most performant option for fetching python types
  • fetchdicts returns a list of dictionary records. Marginally less performant than tuples, but significantly more performant than fetching tuples and creating dictionarys from them.
  • arrow returns the entire result set as an Arrow Table. Best performance, as python type overhead is skipped entirely
  • arrow_batch returns a single Arrow RecordBatch of specified size. Building block for arrow.

Apache Arrow

A query can be executed for every row in an Arrow RecordBatch.

import pyarrow as pa

cur.execute("drop table if exists t1")
cur.execute("create table t1(a int)")
cur.executemany_arrow(
    "insert into t1(a) values(?)",
    pa.RecordBatch.from_arrays([pa.array([1, 2, 3])], ["a"])
)
cur.execute("select * from t1").fetchall()  # [(1,), (2,), (3,)]

Arrow RecordBatches can be used as a table valued parameter for MS SQL.

cur.execute("drop type if exists test_tabletype")
cur.execute("create type test_tabletype as table(a int)")
con.commit()

assert cur.execute(
    "select sum(a) from ? where a <= ?",
    [
        zodbc.ArrowTVP(
            zodbc.ArrowTVPType.from_name("test_tabletype"),
            pa.RecordBatch.from_arrays([pa.array([1, 2, 3])], ["a"]),
        ),
        2,
    ]
).fetchone()[0] == 3

Metadata

Release files for zodbc 0.9.3

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

Source distribution (sdist)

Source distribution for zodbc 0.9.3
File Size Uploaded
zodbc-0.9.3.tar.gz 35.2 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for zodbc 0.9.3
File Interpreter ABI Platform
zodbc-0.9.3-cp314-cp314-manylinux_2_27_x86_64.whl CPython 3.14 CPython 3.14 Linux glibc 2.27+ x86-64 Details
zodbc-0.9.3-cp313-cp313-manylinux_2_27_x86_64.whl CPython 3.13 CPython 3.13 Linux glibc 2.27+ x86-64 Details
zodbc-0.9.3-cp312-cp312-manylinux_2_27_x86_64.whl CPython 3.12 CPython 3.12 Linux glibc 2.27+ x86-64 Details

Total release size: 11.7 MB

Release files / zodbc-0.9.3.tar.gz

Download URL zodbc-0.9.3.tar.gz
Size 35.2 kB
Tags Source
SHA-256 checksum
How to use checksums
4e88ccf0e033a5927641e556316a8ae823779299e6a606d3ec15b0cf5cd2a277
BLAKE2b-256 checksum
How to use checksums
a088116913c0dfb5941f6ec63543aea1cdb7cd2c652918a07dfd1a6fee5fb0f3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.3

Release files / zodbc-0.9.3-cp314-cp314-manylinux_2_27_x86_64.whl

Download URL zodbc-0.9.3-cp314-cp314-manylinux_2_27_x86_64.whl
Size 3.9 MB
Tags CPython 3.14 Linux glibc 2.27+ x86-64
SHA-256 checksum
How to use checksums
3539bb392088998db9b95df063ec66817faa892e366c42a927a6082efee90b7c
BLAKE2b-256 checksum
How to use checksums
b87270dbe3f1f01dc401a961013c895a1969d24f21a139ccdcd358196585d9ce
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.3

Release files / zodbc-0.9.3-cp313-cp313-manylinux_2_27_x86_64.whl

Download URL zodbc-0.9.3-cp313-cp313-manylinux_2_27_x86_64.whl
Size 3.9 MB
Tags CPython 3.13 Linux glibc 2.27+ x86-64
SHA-256 checksum
How to use checksums
29c468c2e64d5d717156eb11d82b86daee170b902f132fac975475d7f510681c
BLAKE2b-256 checksum
How to use checksums
b45ea1156260723dee4c9812c95cd7f7a44441a19145626a5a8009d9bfe32772
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.3

Release files / zodbc-0.9.3-cp312-cp312-manylinux_2_27_x86_64.whl

Download URL zodbc-0.9.3-cp312-cp312-manylinux_2_27_x86_64.whl
Size 3.9 MB
Tags CPython 3.12 Linux glibc 2.27+ x86-64
SHA-256 checksum
How to use checksums
060e011606f37e701a4c435cdb26b37f7fcd32e4f2f1f3edd2e68fe8be5b58e5
BLAKE2b-256 checksum
How to use checksums
89f6c57027340e5accd0cc96d830fba75ec2011f7e68cfdbd41dafed43613518
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.3

Release history Release notifications | RSS feed

This release

0.9.3 This release

4 release files

0.9.2

1 release file

0.9.1

4 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