Supabase Rust Client
A comprehensive, production-ready Rust client library for Supabase. This library provides a clean, type-safe, and efficient interface to interact with all Supabase services.
๐ Features
- ๐ Authentication - Complete auth system with JWT handling, user management, and session persistence
- ๐๏ธ Database - Type-safe PostgREST API client with query builder pattern
- ๐ Storage - Full-featured file storage with upload, download, and transformation capabilities
- โก Realtime - WebSocket subscriptions for live database changes
- ๐ก๏ธ Type Safety - Comprehensive error handling and type definitions
- ๐ Async/Await - Full async support with tokio
- ๐ WASM Support - Full WebAssembly compatibility for web applications
- ๐ฆ Cross-Platform - Works on native (desktop/server) and WASM (web) targets
- ๐งช Well Tested - Extensive unit and integration test coverage
- ๐ Documentation - Complete API documentation and examples
๐ฆ Installation
Add this to your Cargo.toml
:
[]
= "0.2.0"
= { = "1.0", = ["full"] }
Or use cargo to add it:
๐ Quick Start
use *;
async
๐ Usage Guide
Authentication
use *;
let client = new?;
// Sign up new user
let response = client
.auth
.sign_up_with_email_and_password
.await?;
// Sign in existing user
let response = client
.auth
.sign_in_with_email_and_password
.await?;
// Update user profile
let response = client
.auth
.update_user
.await?;
// Sign out
client.auth.sign_out.await?;
Database Operations
use *;
use ;
let client = new?;
// SELECT with filters and ordering
let posts = client
.database
.from
.select
.eq
.gt
.order
.limit
.
.await?;
// INSERT new record
let new_post = Post ;
let inserted = client
.database
.insert
.values?
.returning
.
.await?;
// UPDATE records
let update_data = json!;
let updated = client
.database
.update
.set?
.eq
.returning
.
.await?;
// DELETE records
let deleted = client
.database
.delete
.eq
.returning
.
.await?;
// Call RPC function
let result = client
.database
.rpc
.await?;
Storage Operations
use *;
use Bytes;
let client = new?;
// Create bucket
let bucket = client
.storage
.create_bucket
.await?;
// Upload file
let file_content = from;
let upload_result = client
.storage
.upload
.await?;
// Upload with options
let options = FileOptions ;
let upload_result = client
.storage
.upload
.await?;
// Download file
let file_data = client
.storage
.download
.await?;
// Get public URL
let public_url = client
.storage
.get_public_url;
// Create signed URL
let signed_url = client
.storage
.create_signed_url
.await?;
// List files
let files = client
.storage
.list
.await?;
Realtime Subscriptions
use *;
let client = new?;
let realtime = client.realtime;
// Connect to realtime
realtime.connect.await?;
// Subscribe to all changes on a table
let subscription_id = realtime
.channel
.table
.subscribe
.await?;
// Subscribe to specific events
let insert_subscription = realtime
.channel
.table
.event
.subscribe
.await?;
// Subscribe with filters
let filtered_subscription = realtime
.channel
.table
.filter
.subscribe
.await?;
// Unsubscribe
realtime.unsubscribe.await?;
๐ง Development
This project uses Nix for reproducible development environments.
Prerequisites
- Nix package manager with flakes enabled
- just command runner (included in Nix environment)
Setup
# Enter the development environment
# Or run commands directly
Available Commands
# Show all available commands
# Format code
# Run linter
# Run tests
# Build project
# Run all checks (format, lint, test, build)
# Start local Supabase for testing
# Run examples
Project Structure
supabase-lib-rs/
โโโ src/
โ โโโ lib.rs # Library entry point
โ โโโ client.rs # Main Supabase client
โ โโโ auth.rs # Authentication module
โ โโโ database.rs # Database operations
โ โโโ storage.rs # File storage
โ โโโ realtime.rs # WebSocket subscriptions
โ โโโ error.rs # Error handling
โ โโโ types.rs # Common types and configurations
โโโ examples/ # Usage examples
โโโ tests/ # Integration tests
โโโ flake.nix # Nix development environment
โโโ justfile # Command runner configuration
โโโ CLAUDE.md # Development guidelines
๐งช Testing
This project has a comprehensive testing system with multiple levels of testing:
Unit Tests
# Run unit tests only
# Run with documentation tests
Integration & E2E Tests
# Start local Supabase (requires Docker/Podman)
# Run integration tests
# Run all tests (unit + doc + integration)
Docker/Podman Setup
The project includes a complete local Supabase setup using Docker Compose:
# Start all Supabase services
# Check status
# View logs
# Stop services
# Clean up data
Services provided:
- ๐ Studio: http://localhost:54323 (Web UI)
- ๐ API: http://localhost:54321 (REST + Auth + Realtime)
- ๐๏ธ Database: localhost:54322 (PostgreSQL)
- ๐ Storage: File storage with image processing
- โก Functions: Edge functions runtime
Test Categories
- Unit Tests - Fast, isolated component tests
- Integration Tests - Test individual modules against real Supabase
- E2E Tests - Full workflow scenarios
- Doc Tests - Ensure documentation examples work
All integration tests automatically skip if Supabase is not available, making them safe for CI/CD.
๐ง Current Limitations
While this library provides comprehensive Supabase functionality, some advanced features are planned for future releases:
Authentication
- OAuth Providers: Google, GitHub, Discord, Apple, etc. (planned for v0.3.0)
- Phone Authentication: SMS OTP and phone number sign-in (planned for v0.3.0)
- Multi-Factor Authentication (MFA): TOTP and SMS-based 2FA (planned for v0.4.0)
- Auth Events:
onAuthStateChange
event listeners (planned for v0.3.0) - Anonymous Sign-in: Temporary anonymous user sessions (planned for v0.3.0)
Database
- Logical Operators: Complex
and()
,or()
,not()
query logic (planned for v0.3.0) - Full-Text Search:
textSearch()
and advanced search operators (planned for v0.4.0) - Query Analysis:
explain()
and CSV export functionality (planned for v0.4.0)
Missing Modules
Edge Functions:โ Added in v0.3.0functions.invoke()
for serverless functions- Management API: Project management and admin operations (planned for v0.4.0)
Workarounds
Most limitations can be worked around:
// Instead of OAuth, use magic links or email/password
let auth_response = client.auth
.sign_up_with_email_and_password
.await?;
// Instead of logical operators, use multiple queries or raw SQL
let result = client.database
.rpc
.await?;
// Instead of Edge Functions, use database RPC functions
let function_result = client.database
.rpc
.await?;
The library currently provides ~90% of core Supabase functionality and covers all common use cases for production applications.
๐ Examples
The examples/
directory contains comprehensive examples:
basic_usage.rs
- Overview of all featuresauth_example.rs
- Authentication flowsdatabase_example.rs
- Database operationsstorage_example.rs
- File storage operationsrealtime_example.rs
- WebSocket subscriptions
Run examples with:
๐ WebAssembly (WASM) Support
This library provides full WebAssembly support for web applications! You can use it with frameworks like Dioxus, Yew, or any WASM-based Rust web framework.
WASM Features
- โ Full API compatibility - Same API works on both native and WASM
- โ HTTP client - Uses browser's fetch API automatically
- โ Authentication - Complete auth flow support
- โ Database - All CRUD operations and query builder
- โ Storage - File upload/download (simplified for WASM)
- โ Realtime - WebSocket subscriptions via browser WebSocket API
Building for WASM
# Add WASM target
# Build for WASM
# Build example for WASM
WASM Example
use ;
use *;
pub async
Integration with Web Frameworks
Dioxus:
use *;
use Client;
Yew:
use *;
use Client;
โ๏ธ Configuration
Environment Variables
The library can be configured using environment variables. Copy .env.example
to .env
and fill in your actual values:
Required variables:
SUPABASE_URL
- Your Supabase project URLSUPABASE_ANON_KEY
- Your Supabase anonymous key
Optional variables:
SUPABASE_SERVICE_ROLE_KEY
- Service role key for admin operationsRUST_LOG
- Log level (debug, info, warn, error)RUST_BACKTRACE
- Enable backtrace (0, 1, full)
Getting Your Supabase Keys
- Go to your Supabase Dashboard
- Select your project
- Navigate to Settings > API
- Copy the keys:
- Project URL โ
SUPABASE_URL
- anon public โ
SUPABASE_ANON_KEY
- service_role โ
SUPABASE_SERVICE_ROLE_KEY
(keep this secret!)
- Project URL โ
Custom Configuration
use ;
let config = SupabaseConfig ;
let client = new_with_config?;
๐ค Contributing
We welcome contributions! Please see our Contributing Guidelines for details.
Development Workflow
- Fork the repository
- Create a feature branch
- Make your changes following the coding standards
- Run the full test suite:
just check
- Submit a pull request
Code Standards
- Follow the existing code style
- Add tests for new features
- Update documentation as needed
- Ensure all checks pass:
just check
๐ License
This project is licensed under the MIT License - see the LICENSE file for details.
๐ Links
๐ Acknowledgments
- Supabase for providing an amazing backend platform
- The Rust community for excellent crates and tooling
- Contributors who help improve this library
Made with โค๏ธ for the Rust and Supabase communities