Skip to main content

Python SDK Advanced Features

Data Neuron's Python SDK offers several advanced features to enhance your data querying and management capabilities.

Custom Query Execution

Execute custom SQL queries while still benefiting from Data Neuron's context awareness:

custom_sql = "SELECT * FROM users WHERE signup_date > :date"
params = {"date": "2023-01-01"}
result = dn.execute_custom_query(custom_sql, params)

Batch Processing

Efficiently process multiple queries in a single batch:

queries = [
"How many active users do we have?",
"What was our revenue last month?",
"Who are our top 5 customers by sales?"
]
results = dn.batch_query(queries)

Query Explanation

Get detailed explanations of how Data Neuron interprets and executes queries:

query = "What is our user retention rate?"
result = dn.explain_query(query)
print(result['explanation'])

Context Management

Dynamically switch between different semantic contexts:

dn.set_context("sales_analytics")
sales_result = dn.query("What were our top-selling products?")

dn.set_context("user_engagement")
engagement_result = dn.query("What is our daily active user count?")

Error Handling and Logging

Implement advanced error handling and logging:

import logging

logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)

try:
result = dn.query("Complex query that might fail")
except DataNeuronQueryError as e:
logger.error(f"Query failed: {e}")
# Implement fallback or retry logic

These advanced features allow you to leverage the full power of Data Neuron in your Python applications, enabling more complex and flexible data operations.