Skip to main content

DBConnector Library DocumentationThe DBConnector library is a robust Python-based utility designed to manage multi-database connections dynamically. It integrates with Azure Blob Storage for configuration management and Azure Key Vault for secure credential retrieval. The library supports MySQL, Microsoft SQL Server (MSSQL), and PostgreSQL.Table of ContentsCore ArchitectureInitialization & AuthenticationCore MethodsSecurity FeaturesUsage ExampleCore ArchitectureThe library follows a Singleton-like pattern using a class-level cache to ensure that only one instance of the connector exists per session, optimizing resource usage and connection pooling.Key Components:Azure Blob Storage: Used to store a JSON manifest (datastores_output.json) that defines which databases a specific user/workflow has access to.Azure Key Vault: Stores the sensitive credentials (host, port, username, password) for each database.Connection Dictionary: An internal mapping (connection_object_dict) that stores active connection objects keyed by the database name.Initialization & AuthenticationThe get MethodInstead of standard instantiation, use the @classmethod get to retrieve an instance.Pythonconnector = DBConnector.get(session_id="123", user_id="user_01", workflow_id="wf_abc")

Authentication FlowIdentity: Uses ClientSecretCredential (Service Principal) to authenticate with Azure services.Manifest Fetching: Downloads the datastore list from Azure Blob Storage based on the workflow_id and user_id path.Secret Retrieval: Iterates through the manifest, cleanses the "key" to match Azure naming conventions, and fetches the JSON secret from the Key Vault.Automatic Connection: Based on the datastore_type, it automatically initializes the appropriate driver (mysql-connector, pyodbc, or psycopg2).Core Methods1. Database ExplorationMethodDescriptiondisplay_connections()Returns a string representation of all active DB connections.display_tables(db_name)Returns a list of all base tables in the specified database.get_schema(db_name, table_name)Returns column names, data types, and nullability for a specific table.2. Data Operationsexecute_query(db_name, query): Executes a read-only SQL statement. It returns the result set as a list of tuples.insert_data(db_name, table_name, data): Performs an INSERT operation.data: A dictionary where keys are column names and values are the data to insert.get_data(db_name, table_name, num_rows=5): A convenience method to quickly preview the first few rows of a table.Security FeaturesRead-Only EnforcementThe execute_query method contains a strict safeguard. It checks the beginning of every SQL string against a list of approved Read-Only Prefixes:SELECT, WITH, SHOW, DESCRIBE, DESC, EXPLAINIf a query starts with DELETE, DROP, or UPDATE, the method will return None and refuse execution.Secret SanitizationAzure Key Vault has strict naming requirements (alphanumerics and hyphens only). The library includes a __sanitize_secret_name helper that:Converts spaces and underscores to hyphens.Removes any non-compliant special characters.Usage ExamplePython# 1. Initialize the connector db_manager = DBConnector.get("session_45", "john_doe", "marketing_workflow")

2. List available tables in the 'CustomerDB'

tables = db_manager.display_tables("CustomerDB") print(f"Available tables: {tables}")

3. Fetch data safely

query = "SELECT name, email FROM Users WHERE status = 'active'" results = db_manager.execute_query("CustomerDB", query)

4. Insert a log entry

log_data = {"event": "login", "user_id": 101, "status": "success"} db_manager.insert_data("LogDB", "activity_logs", log_data)

Release files for agenthink 0.1.35

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

Source distribution (sdist)

Source distribution for agenthink 0.1.35
File Size Uploaded
agenthink-0.1.35.tar.gz 10.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for agenthink 0.1.35
File Interpreter ABI Platform
agenthink-0.1.35-py3-none-any.whl Python 3 none any Details

Total release size: 20.8 kB

Release files / agenthink-0.1.35.tar.gz

Download URL agenthink-0.1.35.tar.gz
Size 10.8 kB
Tags Source
SHA-256 checksum
How to use checksums
8c088ab1eac532bd72911f601132b93d55b2de4c50d5d18b6f4fab008b6bff58
BLAKE2b-256 checksum
How to use checksums
905e74b043f6e3f1bc923326a79f087eaeeb4d34ca073807bf37acd193fcdaac
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.3

Release files / agenthink-0.1.35-py3-none-any.whl

Download URL agenthink-0.1.35-py3-none-any.whl
Size 10.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7e2b8107440dfb7b7ccaabcb66ba31c898cfc34a0052c2f34105e46bf6de6324
BLAKE2b-256 checksum
How to use checksums
0fedf3bd86c187c438caa9c8f9aaedba41627155a1483b5710d4ffff363e8525
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.3

Release history Release notifications | RSS feed

This release

0.1.35 This release

2 release files

0.1.34

2 release files

0.1.33

2 release files

0.1.32

2 release files

0.1.31

2 release files

0.1.27

2 release files

0.1.26

2 release files

0.1.25

2 release files

0.1.18

2 release files

0.1.17

2 release files

0.1.16

2 release files

0.1.15

2 release files

0.1.14

2 release files

0.1.13

2 release files

0.1.12

2 release files

0.1.11

2 release files

0.1.10

2 release files

0.1.8

2 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 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