Client Libraries
The Supabase Client makes it simple for developers to build secure and scalable products.
Auth
Create new users using signUp()
. By default, the user will need to verify their email address before logging in.
If confirmations are disabled the response will contain an access token and also a confirmed_at value, otherwise it will just contain a confirmation_sent_at attribute.
- JavaScript
- Python
- Dart
const { error, data } = await supabase.auth.signUp({
email: 'example@email.com',
password: 'example-password',
})
import os
from supabase import create_client, Client
url: str = os.environ.get("SUPABASE_TEST_URL")
key: str = os.environ.get("SUPABASE_TEST_KEY")
supabase: Client = create_client(url, key)
user = supabase.auth.sign_up(
email='example@email.com',
password='example-password',
)
import 'package:supabase/supabase.dart';
void main() async {
final client = SupabaseClient('supabaseUrl', 'supabaseKey');
// Sign up user with email and password
final response = await client
.auth
.signUp('example@email.com', 'example-password');
}
Existing users can log in using signIn()
.
- JavaScript
- Python
- Dart
const { error, data } = await supabase.auth.signIn({
email: 'example@email.com',
password: 'example-password'
})
import os
from supabase import create_client, Client
url: str = os.environ.get("SUPABASE_TEST_URL")
key: str = os.environ.get("SUPABASE_TEST_KEY")
supabase: Client = create_client(url, key)
user = supabase.auth.sign_in(
email='example@email.com',
password='example-password'
)
import 'package:supabase/supabase.dart';
void main() async {
final client = SupabaseClient('supabaseUrl', 'supabaseKey');
// Sign in user with email and password
final response = await client
.auth
.signIn(email: 'example@email.com', password: 'example-password');
}
If there is an email, but no password passed to signIn()
, the user will receive a magic link.
- JavaScript
- Python
- Dart
const { error, data } = await supabase.auth.signIn({
email: 'example@email.com'
})
import os
from supabase import create_client, Client
url: str = os.environ.get("SUPABASE_TEST_URL")
key: str = os.environ.get("SUPABASE_TEST_KEY")
supabase: Client = create_client(url, key)
user = supabase.auth.sign_in(
email='example@email.com'
)
import 'package:supabase/supabase.dart';
void main() async {
final client = SupabaseClient('supabaseUrl', 'supabaseKey');
// Sign in user with email and magic link
final response = await client
.auth
.signIn(email: 'example@email.com');
}
Third party logins are also handled through signIn()
.
- JavaScript
- Python
- Dart
const { user, error } = await supabase.auth.signIn({
// provider can be 'github', 'google', 'gitlab', or 'bitbucket'
provider: 'github'
})
# Not yet implemented
import 'package:supabase/supabase.dart';
void main() async {
final client = SupabaseClient('supabaseUrl', 'supabaseKey');
final response = await client
.auth
.signIn(provider: Provider.github);
}
Managing data
Since Postgres is a Relational database, the client makes it simple to query tables and fetch related data in one round-trip, using select()
.
- JavaScript
- Python
- Dart
const { data, error } = await supabase
.from('countries')
.select(`
name,
cities (
name
)
`)
import os
from supabase import create_client, Client
url: str = os.environ.get("SUPABASE_TEST_URL")
key: str = os.environ.get("SUPABASE_TEST_KEY")
supabase: Client = create_client(url, key)
data = supabase.table('countries').select('name').execute()
import 'package:supabase/supabase.dart';
void main() async {
final client = SupabaseClient('supabaseUrl', 'supabaseKey');
// Query tables and fetch related data in one round-trip, using select()
final response = await client
.from('countries')
.select('name')
.execute();
}
You can do advanced filtering to extract only the data that you need.
- JavaScript
- Python
- Dart
const { data, error } = await supabase
.from('cities')
.select('name, country_id')
.lt('country_id', 100)
.limit(10)
data = supabase.table('cities').select('name, country_id').eq('name', 'Germany').execute()
# Assert we pulled real data.
assert len(data.get("data", [])) > 0
import 'package:supabase/supabase.dart';
void main() async {
final client = SupabaseClient('supabaseUrl', 'supabaseKey');
// When fetching data, use advanced filtering to only extract data, that you need.
final response = await client
.from('cities')
.select('name,country_id')
.lt('country_id', 100)
.limit(10)
.execute();
}
You can create data easily using insert()
.
- JavaScript
- Python
- Dart
const { data, error } = await supabase
.from('cities')
.insert([
{ name: 'The Shire', country_id: 554 },
{ name: 'Rohan', country_id: 555 },
])
data = supabase.table('cities').insert({'name': 'Gotham', 'country_id': 556 }).execute()
# assert if insert response is a success
assert data.get("status_code") in (200, 201)
# bulk insert
data = supabase.table('cities').insert([
{'name': 'Gotham', 'country_id': 556 },
{'name': 'The Shire', 'country_id': 557 }
]).execute()
import 'package:supabase/supabase.dart';
void main() async {
final client = SupabaseClient('supabaseUrl', 'supabaseKey');
// Create data easily, using insert()
final response = await client
.from('cities')
.insert([
{ 'name': 'The Shire', 'country_id': 554 },
{ 'name': 'Rohan', 'country_id': 555 },
])
.execute();
}
Realtime Changes
The Supabase client makes it simple to listen to realtime database changes, using subscribe()
.
- JavaScript
- Python
- Dart
const mySubscription = supabase
.from('countries')
.on('*', payload => {
console.log('Change received!', payload)
})
.subscribe()
# Not yet implemented
import 'package:supabase/supabase.dart';
void main() async {
final client = SupabaseClient('supabaseUrl', 'supabaseKey');
// Listen to realtime database changes, using subscribe()
final response = await client
.from('countries')
.on(SupabaseEventTypes.all, (payload) {
print('Something happened: ${payload.eventType}');
})
.subscribe((String event, {String? errorMsg}) {
print('event: $event error: $errorMsg');
});
}
You can even listen to Row Level changes.
- JavaScript
- Python
- Dart
const mySubscription = supabase
.from('countries:id.eq.200')
.on('UPDATE', handleRecordUpdated)
.subscribe()
# Not yet implemented
import 'package:supabase/supabase.dart';
void main() async {
final client = SupabaseClient('supabaseUrl', 'supabaseKey');
// You can even listen to Row Level changes
final response = await client
.from('countries:id.eq.200')
.on(SupabaseEventTypes.update, (payload) {
print('Something happened: ${payload.eventType}');
})
.subscribe((String event, {String? errorMsg}) {
print('event: $event error: $errorMsg');
});
}
Next steps
- View the Client Docs
- Sign in: app.supabase.com