mirror of
https://github.com/supabase/supabase.git
synced 2026-10-10 20:05:06 +03:00
847 lines
31 KiB
YAML
847 lines
31 KiB
YAML
openref: 0.1
|
|
|
|
info:
|
|
id: reference/supabase-py
|
|
title: Supabase Python Client
|
|
description: |
|
|
|
|
Supabase Python(Community).
|
|
|
|
definition: ../../spec/enrichments/tsdoc_v2/combined.json
|
|
specUrl: https://github.com/supabase/supabase/edit/master/spec/supabase_py_v2.yml
|
|
slugPrefix: '/'
|
|
libraries:
|
|
- name: 'Python'
|
|
id: 'py'
|
|
version: '0.0.1'
|
|
|
|
functions:
|
|
- id: initializing
|
|
description: |
|
|
You can initialize a new Supabase client using the `create_client()` method.
|
|
|
|
The Supabase client is your entrypoint to the rest of the Supabase functionality
|
|
and is the easiest way to interact with everything we offer within the Supabase ecosystem.
|
|
|
|
examples:
|
|
- id: create-client
|
|
name: create_client()
|
|
code: |
|
|
```
|
|
import os
|
|
from supabase import create_client, Client
|
|
|
|
url: str = os.environ.get("SUPABASE_URL")
|
|
key: str = os.environ.get("SUPABASE_KEY")
|
|
supabase: Client = create_client(url, key)
|
|
```
|
|
- id: with-timeout-option
|
|
name: With timeout option
|
|
code: |
|
|
```
|
|
import os
|
|
from supabase import create_client, Client
|
|
|
|
url: str = os.environ.get("SUPABASE_URL")
|
|
key: str = os.environ.get("SUPABASE_KEY")
|
|
supabase: Client = create_client(url, key, options={'timeout': 10})
|
|
```
|
|
|
|
- id: sign-up
|
|
title: 'sign_up()'
|
|
notes: |
|
|
- By default, the user needs to verify their email address before logging in. To turn this off, disable **Confirm email** in [your project](https://supabase.com/dashboard/project/_/auth/providers).
|
|
- **Confirm email** determines if users need to confirm their email address after signing up.
|
|
- If **Confirm email** is enabled, a `user` is returned but `session` is null.
|
|
- If **Confirm email** is disabled, both a `user` and a `session` are returned.
|
|
- By default, when the user confirms their email address, they are redirected to the [`SITE_URL`](https://supabase.com/docs/reference/auth/config#site_url). You can modify your `SITE_URL` or add additional redirect URLs in [your project](https://supabase.com/dashboard/project/_/auth/url-configuration).
|
|
- If sign_up() is called for an existing confirmed user:
|
|
- If **Confirm email** is enabled in [your project](https://supabase.com/dashboard/project/_/auth/providers), an obfuscated/fake user object is returned.
|
|
- If **Confirm email** is disabled, the error message, `User already registered` is returned.
|
|
- To fetch the currently logged-in user, refer to [`getUser()`](/docs/reference/javascript/auth-getuser).
|
|
examples:
|
|
- id: signup
|
|
name: Sign up
|
|
code: |
|
|
```
|
|
res = supabase.auth.sign_up({
|
|
"email": 'example@email.com',
|
|
"password": 'example-password',
|
|
})
|
|
```
|
|
- id: sign-up-with-additional-user-metadata
|
|
name: Sign up with additional user metadata
|
|
code: |
|
|
```
|
|
res = supabase.auth.sign_up({
|
|
"email": 'example@email.com',
|
|
"password": 'example-password',
|
|
"options": {
|
|
"data": {
|
|
"first_name": 'John',
|
|
"age": 27,
|
|
}
|
|
}
|
|
})
|
|
```
|
|
- id: sign-in-with-password
|
|
title: 'sign_in_with_password'
|
|
notes: |
|
|
- Requires either an email and password or a phone number and password.
|
|
examples:
|
|
- id: sign-in-with-email-and-password
|
|
name: Sign in with email and password
|
|
isSpotlight: true
|
|
code: |
|
|
```
|
|
data = supabase.auth.sign_in_with_password({"email": "j0@supabase.io", "password": "testsupabasenow"})
|
|
```
|
|
- id: sign-in-with-phone-and-password
|
|
name: Sign in with phone and password
|
|
isSpotlight: false
|
|
code: |
|
|
```
|
|
data = supabase.auth.sign_in_with_password({"phone": "+1234566", password": "testsupabasenow"})
|
|
# After receiving a SMS with a OTP.
|
|
data = supabase.auth.verify_otp({
|
|
"phone": '+13334445555',
|
|
"token": '123456',
|
|
})
|
|
```
|
|
- id: sign-in-with-otp
|
|
title: 'sign_in_with_otp'
|
|
notes: |
|
|
- Requires either an email or phone number.
|
|
- This method is used for passwordless sign-ins where a OTP is sent to the user's email or phone number.
|
|
- If the user doesn't exist, `sign_in_with_otp()` will signup the user instead. To restrict this behavior, you can set `should_create_user` in `SignInWithPasswordlessCredentials.options` to `false`.
|
|
- If you're using an email, you can configure whether you want the user to receive a magiclink or a OTP.
|
|
- If you're using phone, you can configure whether you want the user to receive a OTP.
|
|
- The magic link's destination URL is determined by the [`SITE_URL`](/docs/reference/auth/config#site_url).
|
|
- See [redirect URLs and wildcards](/docs/guides/auth/overview#redirect-urls-and-wildcards) to add additional redirect URLs to your project.
|
|
- Magic links and OTPs share the same implementation. To send users a one-time code instead of a magic link, [modify the magic link email template](https://supabase.com/dashboard/project/_/auth/templates) to include `{{ .Token }}` instead of `{{ .ConfirmationURL }}`.
|
|
examples:
|
|
- id: sign-in-with-email
|
|
name: Sign in with email
|
|
isSpotlight: true
|
|
description: The user will be sent an email which contains either a magiclink or a OTP or both. By default, a given user can only request a OTP once every 60 seconds.
|
|
code: |
|
|
```
|
|
data = supabase.auth.sign_in_with_otp({
|
|
"email": 'example@email.com',
|
|
"options": {
|
|
"email_redirect_to": 'https://example.com/welcome'
|
|
}
|
|
})
|
|
```
|
|
- id: sign-in-with-sms-otp
|
|
name: Sign in with SMS OTP
|
|
isSpotlight: false
|
|
description: The user will be sent a SMS which contains a OTP. By default, a given user can only request a OTP once every 60 seconds.
|
|
code: |
|
|
```
|
|
data = supabase.auth.sign_in_with_otp({
|
|
phone: '+13334445555',
|
|
})
|
|
```
|
|
- id: sign-in-with-oauth
|
|
title: 'sign_in_with_oauth'
|
|
notes: |
|
|
- This method is used for signing in using a third-party provider.
|
|
- Supabase supports many different [third-party providers](https://supabase.com/docs/guides/auth#providers).
|
|
examples:
|
|
- id: sign-in-using-a-third-party-provider
|
|
name: Sign in using a third-party provider
|
|
isSpotlight: true
|
|
code: |
|
|
```
|
|
data = supabase.auth.sign_in_with_oauth({
|
|
"provider": 'github'
|
|
})
|
|
```
|
|
- id: sign-in-using-a-third-party-provider-with-redirect
|
|
name: Sign in using a third-party provider with redirect
|
|
isSpotlight: false
|
|
description: |
|
|
- When the third-party provider successfully authenticates the user, the provider redirects the user to the URL specified in the `redirectTo` parameter. This parameter defaults to the [`SITE_URL`](/docs/reference/auth/config#site_url). It does not redirect the user immediately after invoking this method.
|
|
- See [redirect URLs and wildcards](/docs/guides/auth/overview#redirect-urls-and-wildcards) to add additional redirect URLs to your project.
|
|
code: |
|
|
```
|
|
data = supabase.auth.sign_in_with_oauth({
|
|
"provider": 'github',
|
|
"options": {
|
|
"redirect_to": 'https://example.com/welcome'
|
|
}
|
|
})
|
|
```
|
|
- id: sign-in-with-scopes
|
|
name: Sign in with scopes
|
|
isSpotlight: false
|
|
description: |
|
|
If you need additional data from an OAuth provider, you can include a space-separated list of scopes in your request to get back an OAuth provider token.
|
|
You may also need to specify the scopes in the provider's OAuth app settings, depending on the provider. The list of scopes will be documented by the third-party provider you are using and specifying scopes will enable you to use the OAuth provider token to call additional APIs supported by the third-party provider to get more information.
|
|
code: |
|
|
```
|
|
data = supabase.auth.sign_in_with_oauth({
|
|
"provider": 'github',
|
|
"options": {
|
|
"scopes": 'repo gist notifications'
|
|
}
|
|
})
|
|
oauth_token = data.session.provider_token # use to access provider API
|
|
```
|
|
- id: sign-out
|
|
title: 'sign_out()'
|
|
notes: |
|
|
- In order to use the `signOut()` method, the user needs to be signed in first.
|
|
examples:
|
|
- id: sign-out
|
|
name: Sign out
|
|
code: |
|
|
```
|
|
res = supabase.auth.sign_out()
|
|
```
|
|
- id: verify-otp
|
|
title: 'verify_otp'
|
|
notes: |
|
|
- The `verify_otp` method takes in different verification types. If a phone number is used, the type can either be `sms` or `phone_change`. If an email address is used, the type can be one of the following: `signup`, `magiclink`, `recovery`, `invite` or `email_change`.
|
|
- The verification type used should be determined based on the corresponding auth method called before `verify_otp` to sign up / sign-in a user.
|
|
examples:
|
|
- id: verify-sms-one-time-password
|
|
name: Verify SMS One-Time Password (OTP)
|
|
code: |
|
|
```
|
|
res = supabase.auth.verify_otp(phone, token)
|
|
```
|
|
- id: get-user
|
|
title: 'get_user'
|
|
notes: |
|
|
- This method gets the user object from the current session.
|
|
- Fetches the user object from the database instead of local session.
|
|
examples:
|
|
- id: get-the-logged-in-user-with-the-current-existing-session
|
|
name: Get the logged in user with the current existing session
|
|
isSpotlight: true
|
|
code: |
|
|
```
|
|
data = supabase.auth.get_user()
|
|
```
|
|
- id: get-the-logged-in-user-with-a-custom-access-token-jwt
|
|
name: Get the logged in user with a custom access token jwt
|
|
isSpotlight: false
|
|
code: |
|
|
```
|
|
data = supabase.auth.get_user(jwt)
|
|
```
|
|
|
|
- id: get-session
|
|
title: 'get_session'
|
|
examples:
|
|
- id: get-session
|
|
name: Get the session data
|
|
code: |
|
|
```
|
|
res = supabase.auth.get_session()
|
|
```
|
|
|
|
- id: set-session
|
|
title: 'set_session()'
|
|
notes: |
|
|
- `setSession()` takes in a refresh token and uses it to get a new session.
|
|
- The refresh token can only be used once to obtain a new session.
|
|
- [Refresh token rotation](/docs/reference/auth/config#refresh_token_rotation_enabled) is enabled by default on all projects to guard against replay attacks.
|
|
- You can configure the [`REFRESH_TOKEN_REUSE_INTERVAL`](https://supabase.com/docs/reference/auth/config#refresh_token_reuse_interval) which provides a short window in which the same refresh token can be used multiple times in the event of concurrency or offline issues.
|
|
- If you are using React Native, you will need to install a Buffer polyfill via a library such as [rn-nodeify](https://github.com/tradle/rn-nodeify) to properly use the library.
|
|
examples:
|
|
- id: set-session
|
|
name: Refresh the session
|
|
description: Sets the session data from refresh_token and returns current session or an error if the refresh_token is invalid.
|
|
code: |
|
|
```
|
|
res = supabase.auth.set_session(access_token, refresh_token)
|
|
```
|
|
- id: refresh-session
|
|
title: 'refresh_session()'
|
|
notes: |
|
|
- This method will refresh the session whether the current one is expired or not.
|
|
- Both examples destructure `user` and `session` from `data`. This is not required; so `const { data, error } =` is also valid.
|
|
examples:
|
|
- id: refresh-session
|
|
name: Refresh session using the current session
|
|
code: |
|
|
```
|
|
res = supabase.auth.refresh_session()
|
|
```
|
|
- id: select
|
|
title: 'Fetch data: select()'
|
|
notes: |
|
|
- By default, Supabase projects return a maximum of 1,000 rows. This setting can be changed in your project's [API settings](https://supabase.com/dashboard/project/_/settings/api). It's recommended that you keep it low to limit the payload size of accidental or malicious requests.
|
|
- `apikey` is a reserved keyword if you're using the [Supabase Platform](/docs/guides/platform) and [should be avoided as a column name](https://github.com/supabase/supabase/issues/5465).
|
|
examples:
|
|
- id: getting-your-data
|
|
name: Getting your data
|
|
code: |
|
|
```
|
|
response = supabase.table('countries').select("*").execute()
|
|
```
|
|
data:
|
|
sql: |
|
|
```sql
|
|
create table
|
|
countries (id int8 primary key, name text);
|
|
|
|
insert into
|
|
countries (id, name)
|
|
values
|
|
(1, 'Afghanistan'),
|
|
(2, 'Albania'),
|
|
(3, 'Algeria');
|
|
```
|
|
response: |
|
|
```
|
|
APIResponse(data=[{'id': 1, 'name': 'Afghanistan'},
|
|
{'id': 2, 'name': 'Albania'},
|
|
{'id': 3, 'name': 'Algeria'}],
|
|
count=None)
|
|
```
|
|
- id: selecting-specific-columns
|
|
name: Selecting specific columns
|
|
code: |
|
|
```
|
|
response = supabase.table('countries').select('name').execute()
|
|
```
|
|
data:
|
|
sql: |
|
|
```sql
|
|
create table
|
|
countries (id int8 primary key, name text);
|
|
|
|
insert into
|
|
countries (id, name)
|
|
values
|
|
(1, 'Afghanistan'),
|
|
(2, 'Albania'),
|
|
(3, 'Algeria');
|
|
```
|
|
response: |
|
|
```
|
|
APIResponse(data=[{'name': 'Afghanistan'},
|
|
{'name': 'Albania'},
|
|
{'name': 'Algeria'}],
|
|
count=None)
|
|
```
|
|
- id: query-foreign-tables
|
|
name: Query foreign tables
|
|
description: |
|
|
If your database has foreign key relationships, you can query related tables too.
|
|
code: |
|
|
```
|
|
response = supabase.table('countries').select('name, cities(name)').execute()
|
|
```
|
|
data:
|
|
sql: |
|
|
```sql
|
|
create table
|
|
countries (id int8 primary key, name text);
|
|
create table
|
|
cities (
|
|
id int8 primary key,
|
|
country_id int8 not null references countries,
|
|
name text
|
|
);
|
|
|
|
insert into
|
|
countries (id, name)
|
|
values
|
|
(1, 'Germany'),
|
|
(2, 'Indonesia');
|
|
insert into
|
|
cities (id, country_id, name)
|
|
values
|
|
(1, 2, 'Bali'),
|
|
(2, 1, 'Munich');
|
|
```
|
|
response: |
|
|
```
|
|
APIResponse(data=[{'name': 'Germany', 'cities': [{'name': 'Munich'}]},
|
|
{'name': 'Indonesia', 'cities': [{'name': 'Bali'}]}],
|
|
count=None)
|
|
```
|
|
- id: query-foreign-tables-through-a-join-table
|
|
name: Query foreign tables through a join table
|
|
code: |
|
|
```
|
|
response = supabase.table('users').select('name, teams(name)').execute()
|
|
```
|
|
data:
|
|
sql: |
|
|
```sql
|
|
create table
|
|
users (
|
|
id int8 primary key,
|
|
name text
|
|
);
|
|
create table
|
|
teams (
|
|
id int8 primary key,
|
|
name text
|
|
);
|
|
-- join table
|
|
create table
|
|
users_teams (
|
|
user_id int8 not null references users,
|
|
team_id int8 not null references teams,
|
|
-- both foreign keys must be part of a composite primary key
|
|
primary key (user_id, team_id)
|
|
);
|
|
|
|
insert into
|
|
users (id, name)
|
|
values
|
|
(1, 'Kiran'),
|
|
(2, 'Evan');
|
|
insert into
|
|
teams (id, name)
|
|
values
|
|
(1, 'Green'),
|
|
(2, 'Blue');
|
|
insert into
|
|
users_teams (user_id, team_id)
|
|
values
|
|
(1, 1),
|
|
(1, 2),
|
|
(2, 2);
|
|
```
|
|
response: |
|
|
```
|
|
APIResponse(data=[
|
|
{'name': 'Kiran', 'teams': [{'name': 'Green'}, {'name': 'Blue'}]},
|
|
{'name': 'Evan', 'teams': [{'name': 'Blue'}]}
|
|
],
|
|
count=None)
|
|
```
|
|
description: |
|
|
If you're in a situation where your tables are **NOT** directly
|
|
related, but instead are joined by a _join table_, you can still use
|
|
the `select()` method to query the related data. The join table needs
|
|
to have the foreign keys as part of its composite primary key.
|
|
hideCodeBlock: true
|
|
- id: query-the-same-foreign-table-multiple-times
|
|
name: Query the same foreign table multiple times
|
|
code: |
|
|
```
|
|
response = supabase.table('messages').select('content,from:sender_id(name),to:receiver_id(name)').execute()
|
|
```
|
|
data:
|
|
sql: |
|
|
```sql
|
|
create table
|
|
users (id int8 primary key, name text);
|
|
|
|
create table
|
|
messages (
|
|
sender_id int8 not null references users,
|
|
receiver_id int8 not null references users,
|
|
content text
|
|
);
|
|
|
|
insert into
|
|
users (id, name)
|
|
values
|
|
(1, 'Kiran'),
|
|
(2, 'Evan');
|
|
|
|
insert into
|
|
messages (sender_id, receiver_id, content)
|
|
values
|
|
(1, 2, '👋');
|
|
```
|
|
response: |
|
|
```
|
|
APIResponse(data=[{'content': '👋',
|
|
'from': {'name': 'Kiran'},
|
|
'to': {'name': 'Evan'}}
|
|
],
|
|
count=None)
|
|
```
|
|
description: |
|
|
If you need to query the same foreign table twice, use the name of the
|
|
joined column to identify which join to use. You can also give each
|
|
column an alias.
|
|
hideCodeBlock: true
|
|
- id: filtering-through-foreign-tables
|
|
name: Filtering through foreign tables
|
|
code: |
|
|
```
|
|
response = supabase.table('cities').select('name, countries(*)').eq('countries.name', 'Estonia').execute()
|
|
```
|
|
data:
|
|
sql: |
|
|
```sql
|
|
create table
|
|
countries (id int8 primary key, name text);
|
|
create table
|
|
cities (
|
|
id int8 primary key,
|
|
country_id int8 not null references countries,
|
|
name text
|
|
);
|
|
|
|
insert into
|
|
countries (id, name)
|
|
values
|
|
(1, 'Germany'),
|
|
(2, 'Indonesia');
|
|
insert into
|
|
cities (id, country_id, name)
|
|
values
|
|
(1, 2, 'Bali'),
|
|
(2, 1, 'Munich');
|
|
```
|
|
response: |
|
|
```
|
|
APIResponse(data=[{'name': 'Bali', 'countries': None},
|
|
{'name': 'Munich', 'countries': None}],
|
|
count=None)
|
|
```
|
|
description: |
|
|
NOT WORKING CURRENTLY
|
|
If the filter on a foreign table's column is not satisfied, the foreign
|
|
table returns `[]` or `null` but the parent table is not filtered out.
|
|
If you want to filter out the parent table rows, use the `!inner` hint
|
|
hideCodeBlock: true
|
|
- id: querying-foreign-table-with-count
|
|
name: Querying foreign table with count
|
|
code: |
|
|
```
|
|
response = supabase.table('countries').select('*, cities(count)').execute()
|
|
```
|
|
data:
|
|
sql: |
|
|
```sql
|
|
create table countries (
|
|
"id" "uuid" primary key default "extensions"."uuid_generate_v4"() not null,
|
|
"name" text
|
|
);
|
|
|
|
create table cities (
|
|
"id" "uuid" primary key default "extensions"."uuid_generate_v4"() not null,
|
|
"name" text,
|
|
"country_id" "uuid" references public.countries on delete cascade
|
|
);
|
|
|
|
with country as (
|
|
insert into countries (name)
|
|
values ('united kingdom') returning id
|
|
)
|
|
insert into cities (name, country_id) values
|
|
('London', (select id from country)),
|
|
('Manchester', (select id from country)),
|
|
('Liverpool', (select id from country)),
|
|
('Bristol', (select id from country));
|
|
```
|
|
response: |
|
|
```
|
|
APIResponse(data=[{'id': 1, 'name': 'Germany', 'cities': [{'count': 1}]},
|
|
{'id': 2, 'name': 'Indonesia', 'cities': [{'count': 1}]}],
|
|
count=None)
|
|
```
|
|
description: |
|
|
You can get the number of rows in a related table by using the
|
|
**count** property.
|
|
hideCodeBlock: true
|
|
- id: querying-with-count-option
|
|
name: Querying with count option
|
|
code: |
|
|
```
|
|
response = supabase.table('countries').select('*', count='exact').execute()
|
|
```
|
|
data:
|
|
sql: |
|
|
```sql
|
|
create table
|
|
countries (id int8 primary key, name text);
|
|
|
|
insert into
|
|
countries (id, name)
|
|
values
|
|
(1, 'Afghanistan'),
|
|
(2, 'Albania'),
|
|
(3, 'Algeria');
|
|
```
|
|
response: |
|
|
```
|
|
APIResponse(data=[{'id': 1, 'name': 'Germany'},
|
|
{'id': 2, 'name': 'Indonesia'}],
|
|
count=2)
|
|
```
|
|
description: |
|
|
You can get the number of rows by using the
|
|
*count* parameter in the select query.
|
|
hideCodeBlock: true
|
|
- id: querying-json-data
|
|
name: Querying JSON data
|
|
code: |
|
|
```
|
|
response = supabase.table('users').select('id, name, address->city').execute()
|
|
```
|
|
data:
|
|
sql: |
|
|
```sql
|
|
create table
|
|
users (
|
|
id int8 primary key,
|
|
name text,
|
|
address jsonb
|
|
);
|
|
|
|
insert into
|
|
users (id, name, address)
|
|
values
|
|
(1, 'Avdotya', '{"city":"Saint Petersburg"}');
|
|
```
|
|
response: |
|
|
```
|
|
APIResponse(data=[{'id': 1, 'name': 'Avdotya', 'city': 'Saint Petersburg'}], count=None)
|
|
```
|
|
description: |
|
|
You can select and filter data inside of
|
|
[JSON](/docs/guides/database/json) columns. Postgres offers some
|
|
[operators](/docs/guides/database/json#query-the-jsonb-data) for
|
|
querying JSON data.
|
|
hideCodeBlock: true
|
|
|
|
- id: insert
|
|
title: 'Create data: insert()'
|
|
$ref: '@supabase/postgrest-js.PostgrestQueryBuilder.insert'
|
|
examples:
|
|
- id: create-a-record
|
|
name: Create a record
|
|
code: |
|
|
```
|
|
data, count = supabase
|
|
.table('countries')
|
|
.insert({"id": 1, "name": "Denmark"})
|
|
.execute()
|
|
```
|
|
data:
|
|
sql: |
|
|
```sql
|
|
create table
|
|
countries (id int8 primary key, name text);
|
|
```
|
|
response: |
|
|
```
|
|
APIResponse(data=[{'id': 1, 'name': 'Denmark'}], count=None)
|
|
```
|
|
hideCodeBlock: true
|
|
isSpotlight: true
|
|
|
|
- id: invoke
|
|
title: 'invoke()'
|
|
description: |
|
|
Invoke a Supabase Function.
|
|
notes: |
|
|
- Requires an Authorization header.
|
|
- When you pass in a body to your function, we automatically attach the Content-Type header for `Blob`, `ArrayBuffer`, `File`, `FormData` and `String`. If it doesn't match any of these types we assume the payload is `json`, serialise it and attach the `Content-Type` header as `application/json`. You can override this behaviour by passing in a `Content-Type` header of your own.
|
|
examples:
|
|
- id: invoke-function
|
|
name: Basic invocation
|
|
description:
|
|
code: |
|
|
```
|
|
func = supabase.functions()
|
|
@asyncio.coroutine
|
|
async def test_func(loop):
|
|
resp = await func.invoke("hello-world",invoke_options={'body':{}})
|
|
return resp
|
|
|
|
loop = asyncio.get_event_loop()
|
|
resp = loop.run_until_complete(test_func(loop))
|
|
loop.close()
|
|
```
|
|
|
|
- id: list-buckets
|
|
title: 'list_buckets()'
|
|
notes: |
|
|
- RLS policy permissions required:
|
|
- `buckets` table permissions: `select`
|
|
- `objects` table permissions: none
|
|
- Refer to the [Storage guide](/docs/guides/storage#access-control) on how access control works
|
|
examples:
|
|
- id: list-buckets
|
|
name: List buckets
|
|
code: |
|
|
```
|
|
res = supabase.storage.list_buckets()
|
|
```
|
|
|
|
- id: get-bucket
|
|
title: 'get_bucket()'
|
|
notes: |
|
|
- RLS policy permissions required:
|
|
- `buckets` table permissions: `select`
|
|
- `objects` table permissions: none
|
|
- Refer to the [Storage guide](/docs/guides/storage#access-control) on how access control works
|
|
examples:
|
|
- id: get-bucket
|
|
name: Get bucket
|
|
code: |
|
|
```
|
|
res = supabase.storage.get_bucket(name)
|
|
```
|
|
|
|
- id: create-bucket
|
|
title: 'create_bucket()'
|
|
notes: |
|
|
- RLS policy permissions required:
|
|
- `buckets` table permissions: `insert`
|
|
- `objects` table permissions: none
|
|
- Refer to the [Storage guide](/docs/guides/storage#access-control) on how access control works
|
|
examples:
|
|
- id: create-bucket
|
|
name: Create bucket
|
|
code: |
|
|
```
|
|
res = supabase.storage.create_bucket(name)
|
|
```
|
|
|
|
- id: empty-bucket
|
|
title: 'empty_bucket()'
|
|
notes: |
|
|
- RLS policy permissions required:
|
|
- `buckets` table permissions: `select`
|
|
- `objects` table permissions: `select` and `delete`
|
|
- Refer to the [Storage guide](/docs/guides/storage#access-control) on how access control works
|
|
examples:
|
|
- id: empty-bucket
|
|
name: Empty bucket
|
|
code: |
|
|
```
|
|
res = supabase.storage.empty_bucket(name)
|
|
```
|
|
- id: delete-bucket
|
|
title: 'delete_bucket()'
|
|
notes: |
|
|
- RLS policy permissions required:
|
|
- `buckets` table permissions: `select` and `delete`
|
|
- `objects` table permissions: none
|
|
- Refer to the [Storage guide](/docs/guides/storage#access-control) on how access control works
|
|
examples:
|
|
- id: delete-bucket
|
|
name: Delete bucket
|
|
code: |
|
|
```
|
|
res = supabase.storage.delete_bucket(name)
|
|
```
|
|
|
|
- id: from-upload
|
|
title: 'from_.upload()'
|
|
notes: |
|
|
- RLS policy permissions required:
|
|
- `buckets` table permissions: none
|
|
- `objects` table permissions: `insert`
|
|
- Refer to the [Storage guide](/docs/guides/storage#access-control) on how access control works
|
|
examples:
|
|
- id: upload-file
|
|
name: Upload file using filepath
|
|
code: |
|
|
```
|
|
with open(source, 'rb+') as f:
|
|
res = supabase.storage.from_('bucket').upload(destination, f)
|
|
```
|
|
- id: from-move
|
|
title: 'from_.move()'
|
|
notes: |
|
|
- RLS policy permissions required:
|
|
- `buckets` table permissions: none
|
|
- `objects` table permissions: `update` and `select`
|
|
- Refer to the [Storage guide](/docs/guides/storage#access-control) on how access control works
|
|
examples:
|
|
- id: move-file
|
|
name: Move file
|
|
code: |
|
|
```
|
|
res = supabase.storage.from_(bucket).move('public/avatar1.png', 'private/avatar2.png')
|
|
```
|
|
|
|
- id: from-create-signed-url
|
|
title: 'from_.create_signed_url()'
|
|
notes: |
|
|
- RLS policy permissions required:
|
|
- `buckets` table permissions: none
|
|
- `objects` table permissions: `select`
|
|
- Refer to the [Storage guide](/docs/guides/storage#access-control) on how access control works
|
|
examples:
|
|
- id: create-signed-url
|
|
name: Create Signed URL
|
|
code: |
|
|
```
|
|
res = supabase.storage.from_(bucket_name).create_signed_url(filepath, expiry_duration)
|
|
```
|
|
|
|
- id: from-get-public-url
|
|
title: 'from_.get_public_url()'
|
|
notes: |
|
|
- The bucket needs to be set to public, either via [updateBucket()](/docs/reference/javascript/storage-updatebucket) or by going to Storage on [supabase.com/dashboard](https://supabase.com/dashboard), clicking the overflow menu on a bucket and choosing "Make public"
|
|
- RLS policy permissions required:
|
|
- `buckets` table permissions: none
|
|
- `objects` table permissions: none
|
|
- Refer to the [Storage guide](/docs/guides/storage#access-control) on how access control works
|
|
examples:
|
|
- id: get-public-url
|
|
name: Returns the URL for an asset in a public bucket
|
|
code: |
|
|
```
|
|
res = supabase.storage.from_(bucket_name).get_public_url('test/avatar1.jpg')
|
|
```
|
|
|
|
- id: from-download
|
|
title: 'from_.download()'
|
|
notes: |
|
|
- RLS policy permissions required:
|
|
- `buckets` table permissions: none
|
|
- `objects` table permissions: `select`
|
|
- Refer to the [Storage guide](/docs/guides/storage#access-control) on how access control works
|
|
examples:
|
|
- id: download-file
|
|
name: Download file
|
|
code: |
|
|
```
|
|
with open(destination, 'wb+') as f:
|
|
res = supabase.storage.from_(bucket_name).download(source)
|
|
f.write(res)
|
|
```
|
|
|
|
- id: from-remove
|
|
title: 'from_.remove()'
|
|
notes: |
|
|
- RLS policy permissions required:
|
|
- `buckets` table permissions: none
|
|
- `objects` table permissions: `delete` and `select`
|
|
- Refer to the [Storage guide](/docs/guides/storage#access-control) on how access control works
|
|
examples:
|
|
- id: delete-file
|
|
name: Delete file
|
|
code: |
|
|
```
|
|
res = supabase.storage.from_('test').remove('test.jpg')
|
|
```
|
|
- id: from-list
|
|
title: 'from_.list()'
|
|
notes: |
|
|
- RLS policy permissions required:
|
|
- `buckets` table permissions: none
|
|
- `objects` table permissions: `select`
|
|
- Refer to the [Storage guide](/docs/guides/storage#access-control) on how access control works
|
|
examples:
|
|
- id: list-files
|
|
name: List files in a bucket
|
|
code: |
|
|
```
|
|
res = supabase.storage.from_('test').list()
|
|
```
|
|
- id: subscribe
|
|
title: on().subscribe()
|
|
notes: |
|
|
- We are implementing this feature at the moment. If you have queries feel free to open an issue on the [realtime-py](https://github.com/supabase-community/realtime-py) repository.
|