Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 58 additions & 20 deletions MIGRATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Abbreviated and contracted public names are spelled out. Wire formats do not cha
| `realtime` | `PresenceOpts` | `PresenceOptions` |
| `realtime` | `VSN` | `PROTOCOL_VERSION` |
| `supabase` | `RealtimeClientOptions` keys `hb_interval`, `hb_timeout` | `heartbeat_interval`, `heartbeat_timeout` |
| `supabase` | `AClient`, `AClientOptions` | `AsyncClient`, `AsyncClientOptions` |
| `supabase` | `AClient` | `AsyncClient` |
| `supabase` | `ASupabaseException` | `SupabaseException` |
| `supabase` | `ASupabaseStorageClient` | `storage3.AsyncStorageClient` |
| `supabase` | `httpx.create_aclient`, `aiohttp.create_aclient` | `httpx.create_async_client`, `aiohttp.create_async_client` |
Expand Down Expand Up @@ -52,45 +52,83 @@ Names that mirror a wire format keep their wire spelling, for example the JWT cl
| `from supabase._async.client import AsyncClient` | `from supabase import AsyncClient` |
| `from supabase._sync.client import Client` | `from supabase import Client` |
| `AsyncSupabaseException`, `SyncSupabaseException` | `SupabaseException` |
| `SyncClientOptions` | `ClientOptions` |
| `supabase.SupabaseStorageClient` | `storage3.SyncStorageClient` |
| `supabase.client.AsyncSupabaseStorageClient` | `storage3.AsyncStorageClient` |
| `client.rpc("fn", {"a": 1}, CountMethod.exact)` | `client.rpc("fn", {"a": 1}, count=CountMethod.exact)` |
| `client.rpc("fn", {"a": 1}, None, True)` | `client.rpc("fn", {"a": 1}, head=True)` |

`ClientOptions` configures `Client` and `AsyncClientOptions` configures `AsyncClient`. `supabase.lib.client_options.ClientOptions` used to be their shared base class and is now the sync options class as well.

`rpc` takes `head`, `count` and `get` as keyword arguments, like `PostgrestClient.rpc`. `params` stays the second positional argument.

`SupabaseException` is one class, so `except SupabaseException` also catches errors raised by `AsyncClient`.

## Client options are keyword arguments

`ClientOptions`, `AsyncClientOptions`, their v2 names `SyncClientOptions` and `AClientOptions`, and the `supabase.lib.client_options` module are removed. `create_client`, `create_async_client`, `Client`, `AsyncClient` and their `create` methods take the settings as keyword-only arguments. Settings that apply to every service are arguments of their own. The settings of one service are grouped in an options class, passed in the argument named after the service.

```python
client = create_client(
url,
key,
headers={"x-app": "1"},
request_timeout=30,
postgrest=PostgrestClientOptions(schema="private"),
auth=AuthClientOptions(flow_type="implicit", session_storage=my_storage),
storage=StorageClientOptions(request_timeout=120),
)
```

| Before | After |
| -------------------------------------------------------------- | ------------------------------------------------------------------ |
| `create_client(url, key, http_client)` | `create_client(url, key, http_client=http_client)` |
| `ClientOptions(headers={"x-app": "1"})` | `headers={"x-app": "1"}` |
| `ClientOptions(request_timeout=30)` | `request_timeout=30` |
| `ClientOptions(schema="private")` | `postgrest=PostgrestClientOptions(schema="private")` |
| `ClientOptions(auto_refresh_token=False)` | `auth=AuthClientOptions(auto_refresh_token=False)` |
| `ClientOptions(storage=my_storage)` | `auth=AuthClientOptions(session_storage=my_storage)` |
| `ClientOptions(flow_type="implicit")` | `auth=AuthClientOptions(flow_type="implicit")` |
| `ClientOptions(persist_session=False)` | Leave it out |
| `ClientOptions(postgrest_options=PostgrestClientOptions(...))` | `postgrest=PostgrestClientOptions(...)` |
| `ClientOptions(auth_options=AuthClientOptions(...))` | `auth=AuthClientOptions(...)` |
| `ClientOptions(storage_options=StorageClientOptions(...))` | `storage=StorageClientOptions(...)` |
| `ClientOptions(functions_options=FunctionsClientOptions(...))` | `functions=FunctionsClientOptions(...)` |
| `AsyncClientOptions(realtime=RealtimeClientOptions(...))` | `realtime=RealtimeClientOptions(...)` |
| `client.options.headers` | `client.headers` |
| `options.replace(schema="other")` | `postgrest=dataclasses.replace(postgrest_options, schema="other")` |

`AuthClientOptions.session_storage` takes an `AsyncSupportedStorage` for `AsyncClient` and a `SyncSupportedStorage` for `Client`. It used to be called `storage`, which clashed with the storage service. Left out, the session is kept in memory.

`persist_session` is removed. It was never passed on to the session manager, so it had no effect. To keep the session only in memory, leave `session_storage` out.

`headers` are sent on top of the default `X-Client-Info` header instead of replacing it. A header you pass with the same name, in any case, still replaces the default one.

`client.headers` is a read-only view of the headers sent with every request. Its `Authorization` header follows the session. The headers you pass are copied, so changing the original dictionary later has no effect.

`PostgrestClientOptions`, `AuthClientOptions`, `StorageClientOptions` and `FunctionsClientOptions` take keyword arguments only.

## Options are dataclasses instead of dictionaries

The remaining option `TypedDict`s are dataclasses. Fields you leave out use the same defaults as before.

| Package | Before | After |
| ---------- | ------------------------------------------------------------ | --------------------------------------------------------------------------- |
| `supabase` | `AsyncClientOptions(realtime={"heartbeat_interval": 30})` | `AsyncClientOptions(realtime=RealtimeClientOptions(heartbeat_interval=30))` |
| `storage3` | `list_v2(sort_by={"column": "created_at", "order": "desc"})` | `list_v2(sort_by=SortByV2(column="created_at", order="desc"))` |
| Package | Before | After |
| ---------- | ------------------------------------------------------------ | -------------------------------------------------------------------------------------- |
| `supabase` | `AsyncClientOptions(realtime={"heartbeat_interval": 30})` | `create_async_client(url, key, realtime=RealtimeClientOptions(heartbeat_interval=30))` |
| `storage3` | `list_v2(sort_by={"column": "created_at", "order": "desc"})` | `list_v2(sort_by=SortByV2(column="created_at", order="desc"))` |

`RealtimeClientOptions` is exported from `supabase`, and `SortByV2` from `storage3.types`. `ClientOptions.realtime` and `AsyncClientOptions.realtime` default to `RealtimeClientOptions()` instead of `None`.
`RealtimeClientOptions` is exported from `supabase`, and `SortByV2` from `storage3.types`.

The unused `storage3.types.SearchV2Options` and `storage3.types.UploadData` are removed.

## Options are frozen

Option and parameter dataclasses are frozen. Setting a field raises `dataclasses.FrozenInstanceError`. Build a changed copy instead, with `replace()` on the client options or with `dataclasses.replace` on the others.

This covers `ClientOptions`, `AsyncClientOptions`, `RealtimeClientOptions`, `realtime.RealtimeChannelOptions`, `realtime.PostgresChangesBinding`, the `storage3.types` `SortByType`, `SortByV2` and `TransformOptions`, and the `supabase_auth` credential and parameter classes such as `SignUpWithEmailAndPasswordCredentials` and `VerifyEmailOtpParams`.
Option and parameter dataclasses are frozen. Setting a field raises `dataclasses.FrozenInstanceError`. Build a changed copy with `dataclasses.replace` instead.

| Before | After |
| ------------------------------------------------------ | ---------------------------------------------------------------------- |
| `options.headers["x-app"] = "1"` | `options = options.replace(headers={**options.headers, "x-app": "1"})` |
| `options.schema = "other"` | `options = options.replace(schema="other")` |
| `options.broadcast(ack=True)` without using the result | `options = options.broadcast(ack=True)` |
| `options.postgres_changes_bindings.append(binding)` | `options = options.postgres_changes(...)` |
This covers `PostgrestClientOptions`, `AuthClientOptions`, `StorageClientOptions`, `FunctionsClientOptions`, `RealtimeClientOptions`, `realtime.RealtimeChannelOptions`, `realtime.PostgresChangesBinding`, the `storage3.types` `SortByType`, `SortByV2` and `TransformOptions`, and the `supabase_auth` credential and parameter classes such as `SignUpWithEmailAndPasswordCredentials` and `VerifyEmailOtpParams`.

`ClientOptions.headers` is typed as a read-only `Mapping`. The options copy the headers they are given, so changing the original dictionary later has no effect. The client no longer changes the options it is given. When the session changes it replaces `client.options` with a copy that has the new `Authorization` header.
| Before | After |
| ------------------------------------------------------ | -------------------------------------------------------- |
| `options.schema = "other"` | `options = dataclasses.replace(options, schema="other")` |
| `options.broadcast(ack=True)` without using the result | `options = options.broadcast(ack=True)` |
| `options.postgres_changes_bindings.append(binding)` | `options = options.postgres_changes(...)` |

The `RealtimeChannelOptions` builder methods return a new copy and leave the original unchanged, so chained calls keep working. `postgres_changes_bindings` and `PostgresChangesBinding.select` are stored as tuples.

Expand All @@ -110,6 +148,6 @@ The client constructors of `supabase_auth`, `postgrest`, `storage3` and `supabas
| ---------------------------------------------- | -------------------------------------------------------------- |
| `SyncStorageClient(url, headers, session, 20)` | `SyncStorageClient(url, headers, session, request_timeout=20)` |

`request_timeout` is in seconds and limits how long a request may go without progress. Set it on `ClientOptions` for every service, on `PostgrestClientOptions`, `AuthClientOptions`, `StorageClientOptions` or `FunctionsClientOptions` for one service, with `request_timeout()` on a database query, or with the `request_timeout` argument of `functions.invoke()`. None, the default, leaves the timeout to the HTTP client.
`request_timeout` is in seconds and limits how long a request may go without progress. Set it with the `request_timeout` argument of the client for every service, on `PostgrestClientOptions`, `AuthClientOptions`, `StorageClientOptions` or `FunctionsClientOptions` for one service, with `request_timeout()` on a database query, or with the `request_timeout` argument of `functions.invoke()`. None, the default, leaves the timeout to the HTTP client.

A timed-out request raises `supabase.RequestTimeoutError`, a subclass of the built-in `TimeoutError`, instead of an httpx or aiohttp exception. This also applies to timeouts configured on the HTTP client.
32 changes: 18 additions & 14 deletions sdk-compliance.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -403,18 +403,18 @@ features:
note: "Every auth event that carries a session sets the Authorization header used by auth, postgrest, storage and functions to that session's access token, and an event without a session resets it to the project key. AsyncClient also passes the token to realtime. The sync Client has no realtime client."
client.authentication_integration.oauth_flow_type:
status: implemented
note: "flow_type option on ClientOptions and the auth client constructor."
note: "flow_type of AuthClientOptions, passed as the auth argument of the supabase client, and of the auth client constructor."
symbols:
- AsyncClientOptions
- ClientOptions
- AuthClientOptions
client.authentication_integration.session_url_detection: not_implemented

client.session_management.custom_storage:
status: implemented
note: "storage option on AsyncClientOptions/ClientOptions and the auth client constructor accepts a custom storage backend."
note: "session_storage of AuthClientOptions, passed as the auth argument of the supabase client, and storage of the auth client constructor accept a custom storage backend."
symbols:
- AsyncSupportedStorage
- SyncSupportedStorage
- AuthClientOptions
supporting_symbols:
- AsyncSupportedStorage.get_item
- AsyncSupportedStorage.remove_item
Expand All @@ -432,7 +432,7 @@ features:
- SyncMemoryStorage.set_item
client.session_management.persist_session:
status: not_implemented
note: "persist_session is accepted by ClientOptions and the auth client constructors but is not forwarded to the session manager, so sessions are always written to storage."
note: "The supabase client has no persist_session setting. The session is kept in session_storage of AuthClientOptions, which defaults to memory. The auth client constructors accept persist_session but do not forward it to the session manager, so sessions are always written to storage."

client.request_configuration.custom_http_client:
status: implemented
Expand All @@ -442,10 +442,14 @@ features:
- create_async_client
client.request_configuration.global_headers:
status: implemented
note: "headers option on ClientOptions, accepted by all sub-client constructors."
note: "headers argument of create_client, create_async_client and the supabase client constructors, accepted by all sub-client constructors. They are sent on top of the default X-Client-Info header. SupabaseClient.headers is a read-only view of the current headers."
symbols:
- AsyncClientOptions
- ClientOptions
- create_client
- create_async_client
- AsyncClient
- Client
supporting_symbols:
- SupabaseClient.headers

client.observability.trace_propagation: not_implemented
client.observability.diagnostic_logging: not_implemented
Expand Down Expand Up @@ -478,6 +482,8 @@ features:
- SyncPostgrestClient.schema
- AsyncClient.schema
- Client.schema
supporting_symbols:
- PostgrestClientOptions
database.query.rpc:
status: implemented
symbols:
Expand Down Expand Up @@ -750,15 +756,15 @@ features:
- BaseRequestClient
database.configuration.request_timeout:
status: implemented
note: "request_timeout (float seconds) on the PostgREST client constructors, and PostgrestClientOptions or the global request_timeout of ClientOptions on the supabase client. request_timeout() on a query overrides it for that query. It bounds how long a request may go without progress, and a timed-out request raises RequestTimeoutError. None (the default) leaves the timeout to the HTTP client."
note: "request_timeout (float seconds) on the PostgREST client constructors, and PostgrestClientOptions or the global request_timeout argument of the supabase client. request_timeout() on a query overrides it for that query. It bounds how long a request may go without progress, and a timed-out request raises RequestTimeoutError. None (the default) leaves the timeout to the HTTP client."
symbols:
- AsyncPostgrestClient
- SyncPostgrestClient
- BaseRequestClient.request_timeout
supporting_symbols:
- PostgrestClientOptions
- ClientOptions
- AsyncClientOptions
- AsyncClient
- Client
database.configuration.access_token:
status: partially_implemented
note: "set_auth(token) sets the bearer token on the client in place; there is no per-request access token option."
Expand Down Expand Up @@ -803,7 +809,7 @@ features:
no_public_symbols: true
functions.invocation.timeout:
status: implemented
note: "request_timeout argument (float seconds) of invoke(), overriding request_timeout of the functions client constructors, and FunctionsClientOptions or the global request_timeout of ClientOptions on the supabase client. It bounds how long the invocation may go without progress, and a timed-out invocation raises RequestTimeoutError. None (the default) leaves the timeout to the HTTP client."
note: "request_timeout argument (float seconds) of invoke(), overriding request_timeout of the functions client constructors, and FunctionsClientOptions or the global request_timeout argument of the supabase client. It bounds how long the invocation may go without progress, and a timed-out invocation raises RequestTimeoutError. None (the default) leaves the timeout to the HTTP client."
symbols:
- FunctionsClient.invoke
supporting_symbols:
Expand Down Expand Up @@ -1365,8 +1371,6 @@ supporting_symbols:
- Client.postgrest
- Client.storage
- Client.functions
- ClientOptions
- AsyncClientOptions
- AuthClientOptions
- StorageClientOptions
- SupabaseException
Expand Down
18 changes: 18 additions & 0 deletions src/supabase/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,24 @@ supabase: Client = create_client(url, key)

For the async client, use `create_async_client` from `supabase.httpx` or `supabase.aiohttp`, which returns an `AsyncClient`.

Settings are keyword arguments. `headers` and `request_timeout` apply to the database, auth, storage and edge functions, not to the realtime connection of `AsyncClient`. The settings of one service are grouped in an options class:

```python
from supabase import AuthClientOptions, PostgrestClientOptions, StorageClientOptions

supabase = create_client(
url,
key,
headers={"x-app": "my-app"},
request_timeout=30,
postgrest=PostgrestClientOptions(schema="private"),
auth=AuthClientOptions(flow_type="implicit"),
storage=StorageClientOptions(request_timeout=120),
)
```

`request_timeout` is in seconds. The `request_timeout` of a service's options overrides the global one for that service.

Use the supabase client to interface with your database.

### Sign-up
Expand Down
Loading
Loading