agenthink 0.1.26__py3-none-any.whl → 0.1.28__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- agenthink/connection.py +2 -2
- agenthink/models.py +1 -1
- agenthink-0.1.28.dist-info/METADATA +31 -0
- agenthink-0.1.28.dist-info/RECORD +9 -0
- {agenthink-0.1.26.dist-info → agenthink-0.1.28.dist-info}/WHEEL +1 -1
- agenthink-0.1.26.dist-info/METADATA +0 -49
- agenthink-0.1.26.dist-info/RECORD +0 -9
- {agenthink-0.1.26.dist-info → agenthink-0.1.28.dist-info}/top_level.txt +0 -0
agenthink/connection.py
CHANGED
|
@@ -55,8 +55,7 @@ class DBConnector:
|
|
|
55
55
|
blob_client = self.__container_client.get_blob_client(blob_path)
|
|
56
56
|
data = blob_client.download_blob().readall()
|
|
57
57
|
except Exception as e:
|
|
58
|
-
logger.exception("Failed to
|
|
59
|
-
container_client = None
|
|
58
|
+
logger.exception("Failed to read datastore blob. Datastore cannot be connected in local setup: %s", e)
|
|
60
59
|
|
|
61
60
|
try:
|
|
62
61
|
# Fallback: if 'data' not present, log and set json_data to empty list
|
|
@@ -367,6 +366,7 @@ class DBConnector:
|
|
|
367
366
|
- Uses `INFORMATION_SCHEMA.TABLES` for MSSQL.
|
|
368
367
|
- Errors are logged and not raised.
|
|
369
368
|
"""
|
|
369
|
+
print(f"{self.connection_object_dict}")
|
|
370
370
|
database_dict = self.connection_object_dict[db_name]
|
|
371
371
|
database_type = database_dict.get("database_type")
|
|
372
372
|
database_connection = database_dict.get("connection_object")
|
agenthink/models.py
CHANGED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: agenthink
|
|
3
|
+
Version: 0.1.28
|
|
4
|
+
Summary: A unified agent framework for connecting workflows, databases, and agents
|
|
5
|
+
Author: Ritobroto
|
|
6
|
+
Requires-Python: >=3.10
|
|
7
|
+
Description-Content-Type: text/markdown
|
|
8
|
+
Requires-Dist: fastapi
|
|
9
|
+
Requires-Dist: mysql-connector-python
|
|
10
|
+
Requires-Dist: azure-identity
|
|
11
|
+
Requires-Dist: azure-keyvault-secrets
|
|
12
|
+
Requires-Dist: azure-storage-blob
|
|
13
|
+
Requires-Dist: pyodbc
|
|
14
|
+
Requires-Dist: python-dotenv
|
|
15
|
+
|
|
16
|
+
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")
|
|
17
|
+
|
|
18
|
+
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
|
|
19
|
+
db_manager = DBConnector.get("session_45", "john_doe", "marketing_workflow")
|
|
20
|
+
|
|
21
|
+
# 2. List available tables in the 'CustomerDB'
|
|
22
|
+
tables = db_manager.display_tables("CustomerDB")
|
|
23
|
+
print(f"Available tables: {tables}")
|
|
24
|
+
|
|
25
|
+
# 3. Fetch data safely
|
|
26
|
+
query = "SELECT name, email FROM Users WHERE status = 'active'"
|
|
27
|
+
results = db_manager.execute_query("CustomerDB", query)
|
|
28
|
+
|
|
29
|
+
# 4. Insert a log entry
|
|
30
|
+
log_data = {"event": "login", "user_id": 101, "status": "success"}
|
|
31
|
+
db_manager.insert_data("LogDB", "activity_logs", log_data)
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
agenthink/__init__.py,sha256=6oUldrZgE76j8OhwsQgVY5vdaPTDFyChOljske-so8U,78
|
|
2
|
+
agenthink/connection.py,sha256=x5-2l_V7o9YJmvnpPVoKNtwjeUYWzApazjt_YNcD7Vk,25506
|
|
3
|
+
agenthink/data_source.py,sha256=hSlpKcS_I6ws9vSKeMnt7EwSHcfO-fFKF8jfXNUE7DI,1196
|
|
4
|
+
agenthink/models.py,sha256=yI3yMV3JTWYHi5c70oVQTr4uHLJTJmf7ep4PzC273xI,1024
|
|
5
|
+
agenthink/utils.py,sha256=r5o74RbenFhQ7E3N7naoLJ-fYEe9otz0nkcvwKHDTaU,911
|
|
6
|
+
agenthink-0.1.28.dist-info/METADATA,sha256=kSgKs5U-X9-pP2qhentlQWm-UBJRzkfS5DK1kVA3FlE,4091
|
|
7
|
+
agenthink-0.1.28.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
|
|
8
|
+
agenthink-0.1.28.dist-info/top_level.txt,sha256=rYw4Lx2uqOzbGCSoJEaikme7vS9NvgbVMc26QUIZoZM,10
|
|
9
|
+
agenthink-0.1.28.dist-info/RECORD,,
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.4
|
|
2
|
-
Name: agenthink
|
|
3
|
-
Version: 0.1.26
|
|
4
|
-
Summary: A unified agent framework for connecting workflows, databases, and agents
|
|
5
|
-
Author: Ritobroto
|
|
6
|
-
Requires-Python: >=3.10
|
|
7
|
-
Description-Content-Type: text/markdown
|
|
8
|
-
Requires-Dist: fastapi
|
|
9
|
-
Requires-Dist: mysql-connector-python
|
|
10
|
-
Requires-Dist: azure-identity
|
|
11
|
-
Requires-Dist: azure-keyvault-secrets
|
|
12
|
-
Requires-Dist: azure-storage-blob
|
|
13
|
-
Requires-Dist: pyodbc
|
|
14
|
-
Requires-Dist: python-dotenv
|
|
15
|
-
|
|
16
|
-
# DBConnector (Agenthink)
|
|
17
|
-
|
|
18
|
-
`DBConnector` is a database connectivity utility for the **Agenthink platform**.
|
|
19
|
-
It enables agents running on Agenthink to securely connect to external **MySQL** and **MSSQL** databases using credentials managed by **Azure Blob Storage** and **Azure Key Vault**.
|
|
20
|
-
|
|
21
|
-
Connections are cached per session and are designed for **read-only access**, allowing agents to safely query data without modifying source databases.
|
|
22
|
-
|
|
23
|
-
## Purpose
|
|
24
|
-
This library allows **Agenthink agents** to:
|
|
25
|
-
- Connect to user-registered databases on the Agenthink platform
|
|
26
|
-
- Execute safe, read-only SQL queries
|
|
27
|
-
- Reuse database connections across agent sessions
|
|
28
|
-
|
|
29
|
-
## Features
|
|
30
|
-
- Session-based connection caching for agents
|
|
31
|
-
- Supports **MySQL** and **MS SQL Server**
|
|
32
|
-
- Secure secret management via **Azure Key Vault**
|
|
33
|
-
- Datastore metadata loaded from **Azure Blob Storage**
|
|
34
|
-
- Read-only SQL enforcement (`SELECT`, `SHOW`, `EXPLAIN`, etc.)
|
|
35
|
-
- Built-in logging for observability and debugging
|
|
36
|
-
|
|
37
|
-
## Basic Usage (Agenthink Agent)
|
|
38
|
-
|
|
39
|
-
```python
|
|
40
|
-
db = DBConnector.get(
|
|
41
|
-
session_id="session_123",
|
|
42
|
-
user_id="user1",
|
|
43
|
-
workflow_id="workflow_A"
|
|
44
|
-
)
|
|
45
|
-
|
|
46
|
-
result = db.execute_query(
|
|
47
|
-
db_name="database_name",
|
|
48
|
-
query="SELECT * FROM item LIMIT 10"
|
|
49
|
-
)
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
agenthink/__init__.py,sha256=6oUldrZgE76j8OhwsQgVY5vdaPTDFyChOljske-so8U,78
|
|
2
|
-
agenthink/connection.py,sha256=sh4sbc7y-BVyCTMMjTSMMEJYeedB6_XBOKpdBb2jKEY,25477
|
|
3
|
-
agenthink/data_source.py,sha256=hSlpKcS_I6ws9vSKeMnt7EwSHcfO-fFKF8jfXNUE7DI,1196
|
|
4
|
-
agenthink/models.py,sha256=PumlTg-5IYkAqx1LJCfeJvHE8XeiOgw6kExSClhbGTU,1035
|
|
5
|
-
agenthink/utils.py,sha256=r5o74RbenFhQ7E3N7naoLJ-fYEe9otz0nkcvwKHDTaU,911
|
|
6
|
-
agenthink-0.1.26.dist-info/METADATA,sha256=8cWbzCDMRSJLHn8fwaAwuqbMpHD1I9OAvKFhV4UgXPc,1722
|
|
7
|
-
agenthink-0.1.26.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
8
|
-
agenthink-0.1.26.dist-info/top_level.txt,sha256=rYw4Lx2uqOzbGCSoJEaikme7vS9NvgbVMc26QUIZoZM,10
|
|
9
|
-
agenthink-0.1.26.dist-info/RECORD,,
|
|
File without changes
|