import xorq as xo
from xorq.vendor.ibis.backends.profiles import Profile
# Create a new profile
= Profile(
profile ="postgres",
con_name=(
kwargs_tuple"host", "${POSTGRES_HOST}"),
("port", 5432),
("database", "postgres"),
("user", "${POSTGRES_USER}"),
("password", "${POSTGRES_PASSWORD}"),
(
),
)
# Create from an existing connection
= Profile.from_con(xo.connect())
profile
# Load from disk by alias
= Profile.load("postgres_example") profile
Profiles API
The Profiles API provides a secure way to manage database connection parameters through environment variable references, allowing you to create, save, load, and use database connections while keeping sensitive information protected.
Profile
A Profile
is an immutable representation of database connection settings that can be serialized to disk.
Properties
Property | Type | Description |
---|---|---|
con_name |
str |
Backend name (e.g., ‘postgres’, ‘snowflake’) |
kwargs_tuple |
tuple |
Connection parameters as key-value pairs |
kwargs_dict |
dict |
Connection parameters as a dictionary |
hash_name |
str |
Unique hash identifier for the profile |
idx |
int |
Unique numeric identifier |
Creation Methods
Instance Methods
# Create a connection
= profile.get_con()
connection
# Create a modified copy
= profile.clone(**{"connect_timeout": 10})
modified
# Convert to dictionary
= profile.as_dict()
profile_dict
# Serialize as JSON
= profile.as_json()
json_str
# Serialize as YAML
= profile.as_yaml()
yaml_str
# Save to disk with optional alias
= profile.save(alias="postgres_example", clobber=True) path
Profiles
A collection manager for working with multiple saved profiles.
from xorq.vendor.ibis.backends.profiles import Profiles
# Create a profiles manager
= Profiles() profiles
Methods
# List all available profiles
= profiles.list()
available
# Get profile by name
= profiles.get("postgres_example")
profile
# Access profiles as attributes
= profiles.postgres_example
profile
# Access profiles as dictionary keys
= profiles["postgres_example"] profile
Environment Variable Handling
Profiles store references to environment variables, not their values:
import os
# Set environment variables
"POSTGRES_HOST"] = "examples.letsql.com"
os.environ["POSTGRES_USER"] = "letsql"
os.environ["POSTGRES_PASSWORD"] = "letsql"
os.environ[
# Create profile with environment variable references
= Profile(
profile ="postgres",
con_name=(
kwargs_tuple"host", "${POSTGRES_HOST}"),
("port", 5432),
("database", "postgres"),
("user", "${POSTGRES_USER}"),
("password", "${POSTGRES_PASSWORD}"),
(
),
)
# Profile stores references (${POSTGRES_PASSWORD}), not actual values
print(profile.kwargs_dict["password"])
# Connection resolves environment variables when created
= profile.get_con() conn
Common Patterns
Creating and Using Profiles
# Create profile
= Profile(
profile ="postgres",
con_name=(
kwargs_tuple"host", "${POSTGRES_HOST}"),
("port", 5432),
("database", "postgres"),
("user", "${POSTGRES_USER}"),
("password", "${POSTGRES_PASSWORD}"),
(
),
)
# Save profile
="postgres_example", clobber=True)
profile.save(alias
# Load profile
= Profile.load("postgres_example")
loaded_profile
# Create connection
= loaded_profile.get_con()
connection
# Use connection
= connection.list_tables() tables
Cloning and Modifying Profiles
# Clone with modifications
= profile.clone(**{"connect_timeout": 10})
cloned_profile
# Save modified profile
="postgres_other_db", clobber=True) cloned_profile.save(alias
Working with Multiple Profiles
# Get profiles collection
= Profiles()
profiles
# List all profiles
= profiles.list()
all_profiles
# Access by name
= profiles.get("postgres_example") my_profile
Security Considerations
- Profiles never store actual values of environment variables, only references
- Sensitive information is resolved only when connections are created
- Profiles can be safely committed to version control
- Always use environment variables for passwords, API keys, and tokens