
Security News
Meet Socket at Black Hat Europe and BSides London 2025
Socket is heading to London! Stop by our booth or schedule a meeting to see what we've been working on.
syne-sql-extension
Advanced tools
Enterprise-grade Jupyter extension for secure SQL query execution through internal services
A powerful Jupyter extension designed to work seamlessly with the SyneHQ.com data platform, providing secure access to your connected data sources without the need for managing database credentials.
This extension is specifically built for the SyneHQ.com data platform, which provides:
pip install syne-sql-extension
git clone https://github.com/synehq/jupyter-sql-extension.git
cd jupyter-sql-extension
pip install -e .
%load_ext syne_sql_extension
# Option 1: Set global variable (recommended for Jupyter notebooks)
SYNE_OAUTH_KEY = 'your_api_key_here'
# Option 2: Use environment variable
# export SYNE_OAUTH_KEY='your_api_key_here'
# Option 3: Provide via command line (most explicit)
%%sql my_database --api-key your_api_key_here
SELECT * FROM users LIMIT 10
%%sql my_database
SELECT * FROM users LIMIT 10
# Assign results to a variable
%%sql analytics_db --output users_df
SELECT user_id, name, email, created_at
FROM users
WHERE created_at >= '2024-01-01'
user_limit = 100
department = 'engineering'
%%sql hr_db
SELECT * FROM employees
WHERE department = {department}
LIMIT {user_limit}
# DataFrame output (default)
%%sql sales_db --format dataframe
SELECT product, SUM(revenue) as total_revenue
FROM sales
GROUP BY product
# HTML table
%%sql sales_db --format html
SELECT * FROM products WHERE price > 100
# JSON output
%%sql api_db --format json
SELECT config FROM settings WHERE active = true
The extension supports multiple ways to provide your SyneHQ API key for authentication. The API key is resolved in the following order of preference:
%%sql my_db --api-key your_api_key_here
SELECT * FROM users LIMIT 10
# Set once at the beginning of your notebook
SYNE_OAUTH_KEY = 'your_api_key_here'
# Then use without specifying the key
%%sql my_db
SELECT * FROM users LIMIT 10
# Set in your shell environment
export SYNE_OAUTH_KEY='your_api_key_here'
# Or in your Jupyter environment
import os
os.environ['SYNE_OAUTH_KEY'] = 'your_api_key_here'
# Simple select
%%sql main_db
SELECT COUNT(*) as total_users FROM users
# Join multiple tables
%%sql warehouse
SELECT
u.name,
p.product_name,
o.order_date,
o.amount
FROM users u
JOIN orders o ON u.id = o.user_id
JOIN products p ON o.product_id = p.id
WHERE o.order_date >= '2024-01-01'
# Load data into DataFrame
%%sql analytics
sales_data >> SELECT
DATE(order_date) as date,
product_category,
SUM(amount) as daily_revenue,
COUNT(*) as order_count
FROM orders
WHERE order_date >= '2024-01-01'
GROUP BY DATE(order_date), product_category
ORDER BY date DESC
# Analyze the data
print(f"Total revenue: ${sales_data['daily_revenue'].sum():,.2f}")
print(f"Average daily orders: {sales_data['order_count'].mean():.1f}")
# Create visualization
sales_data.groupby('product_category')['daily_revenue'].sum().plot(kind='bar')
# Using Python variables in queries with enhanced syntax
start_date = '2024-01-01'
end_date = '2024-12-31'
min_revenue = 1000
user_ids = [1, 2, 3, 4, 5]
# Simple variable substitution
%%sql finance
SELECT
customer_id,
SUM(amount) as total_spent
FROM transactions
WHERE transaction_date BETWEEN {start_date} AND {end_date}
GROUP BY customer_id
HAVING SUM(amount) >= {min_revenue}
ORDER BY total_spent DESC
# List variables with automatic formatting
%%sql analytics
SELECT * FROM users WHERE id IN {user_ids}
# Type-specific formatting
%%sql analytics
SELECT * FROM users WHERE id IN {user_ids:list}
# Expression evaluation
%%sql finance
SELECT * FROM products WHERE price = {min_revenue * 1.5}
# Complex expressions with functions
from datetime import datetime, timedelta
%%sql analytics
SELECT * FROM users WHERE created_at >= {datetime.now() - timedelta(days=30)}
The extension provides comprehensive Python variable substitution in SQL queries with multiple syntax options and safety features.
user_id = 123
user_name = "John Doe"
%%sql my_connection -k my_key
SELECT * FROM users WHERE id = {user_id}
SELECT * FROM users WHERE name = {user_name}
user_ids = [1, 2, 3, 4, 5]
price = 99.99
created_date = datetime(2024, 1, 1)
%%sql my_connection -k my_key
SELECT * FROM users WHERE id IN {user_ids:list}
SELECT * FROM products WHERE price = {price:number}
SELECT * FROM users WHERE created_at >= {created_date:date}
base_price = 100
discount_rate = 0.1
tax_rate = 0.08
%%sql my_connection -k my_key
SELECT * FROM products WHERE final_price = {base_price * (1 - discount_rate) * (1 + tax_rate)}
from datetime import datetime, timedelta
%%sql my_connection -k my_key
SELECT * FROM users WHERE created_at >= {datetime.now() - timedelta(days=30)}
SELECT * FROM products WHERE rounded_price = {round(99.99 * 1.15, 2)}
import, exec, eval are blockedos, sys, subprocess are blocked# Set up variables
start_date = datetime(2024, 1, 1)
end_date = datetime(2024, 12, 31)
min_age = 18
max_age = 65
active_statuses = ['active', 'premium']
excluded_users = [999, 1000, 1001]
# Complex query with multiple variable types
%%sql analytics_db -k my_key
SELECT
u.id,
u.name,
u.email,
u.age,
u.status,
COUNT(o.id) as order_count,
SUM(o.total) as total_spent
FROM users u
LEFT JOIN orders o ON u.id = o.user_id
WHERE u.created_at BETWEEN {start_date:date} AND {end_date:date}
AND u.age BETWEEN {min_age} AND {max_age}
AND u.status IN {active_statuses:list}
AND u.id NOT IN {excluded_users:list}
GROUP BY u.id, u.name, u.email, u.age, u.status
HAVING COUNT(o.id) > 0
ORDER BY total_spent DESC
LIMIT 100
For detailed documentation on Python variable support, see PYTHON_VARIABLE_SUPPORT.md.
# List available connections
%%sql --list-connections -k {key}
# Test if connection is working
%%sql {connection_id}
SELECT 1
The extension provides comprehensive error handling with user-friendly messages:
%%sql invalid_db
SELECT * FROM nonexistent_table
Common error scenarios:
# ❌ This will be blocked
user_input = "'; DROP TABLE users; --"
%%sql db
SELECT * FROM users WHERE name = '{user_input}'
# ✅ Use parameter binding instead
user_input = "John Doe"
%%sql db
SELECT * FROM users WHERE name = {user_input}
The extension automatically validates queries for:
# Enable caching for repeated queries
%%sql db --cache
SELECT expensive_aggregation() FROM large_table
# Run multiple queries concurrently
import asyncio
async def run_queries():
tasks = []
for db in ['db1', 'db2', 'db3']:
task = execute_query(f"%%sql {db}\nSELECT COUNT(*) FROM table")
tasks.append(task)
results = await asyncio.gather(*tasks)
return results
Extension not loading:
# Check if extension is properly installed
%load_ext syne_sql_extension
Connection failures:
Query errors:
# Enable debug logging
%%sql db --debug
SELECT * FROM users
| Option | Description | Default |
|---|---|---|
--connection-id | SyneHQ connection identifier | Required |
--api-key | SyneHQ API key for authentication | Auto-detected |
--output | Variable name for query results | None |
--format | Output format (dataframe, html, json) | dataframe |
--timeout | Query timeout in seconds | 30 |
--cache | Enable query caching | false |
--debug | Enable debug logging | false |
--test | Test connection without executing query | false |
| Setting | Description | Default |
|---|---|---|
api_url | SyneHQ API endpoint | https://api.synehq.com |
timeout | Default query timeout | 30 |
retry_attempts | Number of retry attempts | 3 |
cache_enabled | Enable query caching | true |
cache_ttl | Cache time-to-live (seconds) | 300 |
output_format | Default output format | dataframe |
We welcome contributions! Please see our Contributing Guide for details.
git clone https://github.com/synehq/jupyter-sql-extension.git
cd jupyter-sql-extension
pip install -e ".[dev]"
pre-commit install
pytest tests/
This project is licensed under the MIT License - see the LICENSE file for details.
Made with ❤️ by the SyneHQ team
FAQs
Enterprise-grade Jupyter extension for secure SQL query execution through internal services
We found that syne-sql-extension demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Socket is heading to London! Stop by our booth or schedule a meeting to see what we've been working on.

Security News
OWASP’s 2025 Top 10 introduces Software Supply Chain Failures as a new category, reflecting rising concern over dependency and build system risks.

Research
/Security News
Socket researchers discovered nine malicious NuGet packages that use time-delayed payloads to crash applications and corrupt industrial control systems.