Skip to main content

Python module for uploading numpy arrays to MS SQL Server

This module allows dictionaries of numpy arrays to be uploaded to SQL Server as database tables. The upload is carried out as a bulk insert, which copies binary data to the server without any conversion to or from text. This is faster than uploading text and exactly preserves floating point values.

Compilation

The module uses freetds to communicate with the database server. To build the module, set the location of the freetds library and headers and then run pip install. E.g.:

SYBDB=/cosma/local/freetds/1.4.20/ LDFLAGS="-L${SYBDB}/lib/ -Wl,-rpath=${SYBDB}/lib/" CFLAGS="-I${SYBDB}/include/" pip install .

Usage

Connect to the database:

dbcon = pybcp.DBConnection(username, server, database, password=None)

Here, username and password are the database username and password. server is the server name defined in freetds.conf and database is the name of the database which contains the table to be created or updated.

If the password is None then a password prompt will appear.

Uploading a database table

dbcon.bulk_insert(table_name, columns, create_table=True, drop_existing=True)

Here, table_name is the name of the table to create or append to. columns is a dict of numpy arrays with the data for each column. If create_table is true then a new table will be created. If drop_existing is true then any existing table is removed first.

Table column arrays should be stored in an OrderedDict if the ordering of the columns is important.

Executing SQL commands

For convenience there's a function to execute SQL commands:

dbcon.execute(sql)

where sql is a string with the command to execute. This can be useful for creating indexes on newly uploaded tables, for example.

This returns a list containing any tables returned by the command. Any returned tables are represented as dictionaries of arrays in the same way as data to be bulk inserted.

Release files for pybcp 0.1.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 pybcp 0.1.3
File Size Uploaded
pybcp-0.1.3.tar.gz 23.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pybcp 0.1.3
File Interpreter ABI Platform
pybcp-0.1.3-cp312-cp312-manylinux_2_34_x86_64.whl CPython 3.12 CPython 3.12 Linux glibc 2.34+ x86-64 Details

Total release size: 3.0 MB

Release files / pybcp-0.1.3.tar.gz

Download URL pybcp-0.1.3.tar.gz
Size 23.5 kB
Tags Source
SHA-256 checksum
How to use checksums
0245349a26b3c4b496c852d76a8948eb436c0d1d1a52b8305dd9aed9f906a9a3
BLAKE2b-256 checksum
How to use checksums
dca970a3a6976071fec6d1532916e108554d27c11060d867f40c719fdb4bbcb3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.4

Release files / pybcp-0.1.3-cp312-cp312-manylinux_2_34_x86_64.whl

Download URL pybcp-0.1.3-cp312-cp312-manylinux_2_34_x86_64.whl
Size 3.0 MB
Tags CPython 3.12 Linux glibc 2.34+ x86-64
SHA-256 checksum
How to use checksums
dad8c89091cfadd1aa9b1491db0a559019487c78ce055282de7596a0677222ab
BLAKE2b-256 checksum
How to use checksums
68bf10bbd29b49fb7cb47080dd307d44f646f34a77437627399789212aebe52d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.4

Release history Release notifications | RSS feed

This release

0.1.3 This release

2 release files

0.1.2

2 release files

0.1.1

1 release file

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