Overview
odbc tools is a set of tools to simplify connecting to and working with an ODBC data source. It includes a context manager for handling connections to the data source and the ability to return a result set in an easy to use format or write the results to a file.
Install It
From PyPI
$ pip install odbctools
Use It
Odbctools by default uses a file called config.ini, or you can override this for different scenarios, including passing the dsn directly.
Create config.ini
[odbc] DSN=SourceName
Code Example
from odbctools import OdbcManager
query_string = "Your query here"
params = [p1, p2]
with OdbcManager() as datasource:
result_list = datasource.get_dictionaries(query_string, params)
for result_dict in result_list:
for col_name, col_data in result_dict.items():
print("{0}{1}".format(str(col_name).ljust(25), col_data))
Another Example
from odbctools import OdbcManager
query_string = "Your query here"
params = [p1, p2]
with OdbcManager(dsn='ODBC Name Here') as datasource:
result_list = datasource.get_dictionaries_in_queue(query_string, params)
for result_dict in result_list:
for col_name, col_data in result_dict.items():
print("{0}{1}".format(str(col_name).ljust(25), col_data))
Encapsulating the connection in your classes is also possible
class Foo:
def __init__(self):
self.connection = OdbcManager(dsn='unity64')
def __enter__(self):
self.connection.open_connection()
return self
def __exit__(self, exc_type, exc_val, exc_tb):
self.connection.close_connection()
with Foo() as f:
data = f.connection.get_dictionaries('select top 1 * from people', list())
Note: You can now create a OdbcManager object with a connection string, passing in the connection_string argument.
Returning data from a query
query - Returns list that contains [0]A list containing the query columns [1:] A list of the resulting data (rows)
get_dictionaries - Queries data source, returns a list of dictionaries.
get_dictionaries_in_queue - Queries data source, returns a deque of dictionaries.
write_to_csv - Queries data source and writes results to a CSV file
Updating data
Note: by default commit is turned off, if you want to enable auto commit, you can set it when creating the OdbcManager object or when calling this function.
query_no_resultset - For running DDL/DML queries for creating, deleting, updating records.
Dependencies
pypyodbc
License
MIT
Metadata
Release files for odbctools 0.7.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| odbctools-0.7.1.tar.gz | 28.2 kB | Without provenance | Details for odbctools-0.7.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| odbctools-0.7.1-py3-none-any.whl | Python 3 | none | any | Details for odbctools-0.7.1-py3-none-any.whl |
Total release size: 56.6 kB
Release files / odbctools-0.7.1.tar.gz
| Download URL | odbctools-0.7.1.tar.gz |
|---|---|
| Size | 28.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
61e6661d0066fb21bdbe4b723608aff71fb9755eb22b846d06bf026198116fc8
|
|
BLAKE2b-256 checksum How to use checksums |
87e65045dd449e3c45bf3e2b5cfe153c020f88d1d31cb39e9a77431d50367384
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.7.13
|
Release files / odbctools-0.7.1-py3-none-any.whl
| Download URL | odbctools-0.7.1-py3-none-any.whl |
|---|---|
| Size | 28.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f8c98b8c181105772649ec7f2f15a181faecb9a802c4d1660e9548edc9d47112
|
|
BLAKE2b-256 checksum How to use checksums |
81006c6f3f50cd354e56f420a873ffd95324c9f12270e546e122f815d67a6e88
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.7.13
|
Security for odbctools 0.7.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.