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
- ๐งช Well Tested - Extensive unit and integration test coverage
- ๐ Documentation - Complete API documentation and examples
๐ฆ Installation
Add this to your Cargo.toml
:
[]
= "0.1.1"
= { = "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
# Run unit tests
# Run integration tests (requires Supabase setup)
# Run with coverage
Integration Tests
To run integration tests, you need a Supabase instance:
-
Set up a local Supabase instance:
-
Or configure environment variables for your Supabase project:
-
Run the tests:
๐ 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:
โ๏ธ 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