Installation Guide¶
This guide covers installing surql and setting up SurrealDB for development.
Table of Contents¶
Requirements¶
Python¶
- Python 3.12 or higher
- pip or uv package manager
Check your Python version:
SurrealDB¶
- SurrealDB 1.0 or higher
Installing surql¶
Using pip¶
Using uv (Recommended)¶
uv is a fast Python package installer and resolver.
From Source¶
For development or to use the latest features:
# Clone the repository
git clone https://github.com/Oneiriq/surql-py.git
cd surql
# Install with uv
uv sync
# Or with pip
pip install -e .
Installing SurrealDB¶
macOS¶
Using Homebrew:
Linux¶
Windows¶
Using PowerShell:
Using WSL or Git Bash:
Docker¶
Verify SurrealDB Installation¶
You should see output similar to:
Running SurrealDB¶
Local Development¶
Start SurrealDB in memory mode (data is not persisted):
Start with file storage:
Start with RocksDB (recommended for production):
Using Docker¶
docker run --rm --pull always -p 8000:8000 \
surrealdb/surrealdb:latest \
start --user root --pass root memory
With persistent storage:
docker run --rm --pull always -p 8000:8000 \
-v $(pwd)/mydb:/mydb \
surrealdb/surrealdb:latest \
start --user root --pass root file://mydb/db.surreal
Using Docker Compose¶
Create a docker-compose.yml file:
version: '3.8'
services:
surrealdb:
image: surrealdb/surrealdb:latest
ports:
- "8000:8000"
command: start --user root --pass root memory
# For persistent storage:
# volumes:
# - ./data:/data
# command: start --user root --pass root file://data/db.surreal
Start the service:
Configuration¶
Environment Variables¶
Create a .env file in your project root:
# Database Connection
SURREAL_URL=ws://localhost:8000/rpc
SURREAL_NAMESPACE=test
SURREAL_DATABASE=test
SURREAL_USERNAME=root
SURREAL_PASSWORD=root
# Connection Pool
SURREAL_MAX_CONNECTIONS=10
# Retry Configuration
SURREAL_RETRY_MAX_ATTEMPTS=3
SURREAL_RETRY_MIN_WAIT=1.0
SURREAL_RETRY_MAX_WAIT=10.0
SURREAL_RETRY_MULTIPLIER=2.0
# Logging
LOG_LEVEL=INFO
Python Configuration¶
Create a configuration file in your project:
from surql.connection.config import ConnectionConfig
config = ConnectionConfig(
url='ws://localhost:8000/rpc',
namespace='test',
database='test',
username='root',
password='root',
max_connections=10,
)
Loading from Environment¶
surql automatically loads configuration from environment variables:
from surql.settings import get_db_config
# Loads from environment variables
config = get_db_config()
Verification¶
Verify surql Installation¶
You should see the CLI help output:
Usage: surql [OPTIONS] COMMAND [ARGS]...
surql - Code-first database toolkit for SurrealDB.
Options:
--verbose, -v Enable verbose logging
--help Show this message and exit.
Commands:
db Database management commands
migrate Database migration commands
schema Schema inspection commands
version Show surql version information
Test Database Connection¶
Create a test script test_connection.py:
import asyncio
from surql.connection.client import get_client
from surql.connection.config import ConnectionConfig
async def test_connection():
config = ConnectionConfig(
url='ws://localhost:8000/rpc',
namespace='test',
database='test',
username='root',
password='root',
)
async with get_client(config) as client:
result = await client.execute('SELECT * FROM $session')
print('Connected successfully!')
print(f'Session info: {result}')
if __name__ == '__main__':
asyncio.run(test_connection())
Run the test:
Using the CLI¶
Project Setup¶
Initialize Migration Directory¶
Create a migrations directory in your project:
Create First Migration¶
This creates a migration file in migrations/ with the current timestamp.
Project Structure¶
Your project should look like this:
my-project/
├── .env # Environment variables
├── migrations/ # Migration files
│ └── 20260102_120000_initial_setup.py
├── schemas/ # Schema definitions (optional)
│ └── user.py
└── main.py # Your application
Troubleshooting¶
Connection Refused¶
If you get a connection refused error:
-
Ensure SurrealDB is running:
-
Check the URL matches your SurrealDB instance:
-
Verify port 8000 is not blocked by firewall
Import Errors¶
If you get import errors:
Permission Errors¶
If you get permission errors on Linux/macOS:
# Run with sudo (not recommended for pip)
sudo pip install oneiriq-surql
# Or use virtual environment (recommended)
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
pip install oneiriq-surql
SurrealDB Not Found¶
If surreal command is not found after installation:
- Check if the binary is in your PATH:
-
Add to PATH or use full path to binary
-
On Windows, restart your terminal after installation
Next Steps¶
Now that you have surql installed and configured:
- Follow the Quick Start Tutorial to create your first schema and migration
- Read the Schema Definition Guide to learn about schema features
- Explore the Query Builder & ORM Guide for data operations
- Check out the Examples for working code samples