Skip to main content

A unified agent framework for connecting workflows, databases, and agents

Project description

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)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

agenthink-0.1.31.tar.gz (10.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

agenthink-0.1.31-py3-none-any.whl (10.0 kB view details)

Uploaded Python 3

File details

Details for the file agenthink-0.1.31.tar.gz.

File metadata

  • Download URL: agenthink-0.1.31.tar.gz
  • Upload date:
  • Size: 10.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.3

File hashes

Hashes for agenthink-0.1.31.tar.gz
Algorithm Hash digest
SHA256 f16c9e7ff91eba86d5fd8b0a3a22826824f5905183b9685547769a6bb9ef781c
MD5 4d6cd6ce0fec59c7086ac92d0ad5207f
BLAKE2b-256 5f1a12bdb5c36a70014596a3603faa1d57f2385dbb3ee40c8f7a1b84e8df6ed6

See more details on using hashes here.

File details

Details for the file agenthink-0.1.31-py3-none-any.whl.

File metadata

  • Download URL: agenthink-0.1.31-py3-none-any.whl
  • Upload date:
  • Size: 10.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.3

File hashes

Hashes for agenthink-0.1.31-py3-none-any.whl
Algorithm Hash digest
SHA256 e78a19df4e424cc253fbe192bd514df52d43a6726073e6ed76869b36404c99e7
MD5 bb0cc0ddaabc62970c5a271cba0250a5
BLAKE2b-256 a70eeb3ce27af1a2bb1bbc3bcdfdc11e60a769dc09265487821774487ab51b4b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page