Supabase Python
As the Supabase community has grown, so has demand for a diverse collection of client libraries and framework specific SDKs. This demand for the most part has been serviced by the open source community itself, which currently maintains dozens of libraries.
⚡️ More on Launch Week
When folks make requests to the hosted Supabase service we're able to build up a good picture of how broadly some of these libraries are used, and when a particular library achieves broad adoption it makes sense for us to add official support for it. Examples of libraries that have made the leap from community supported to officially supported include supabase-flutter and supabase-swift.
There has always been incredible community support for the Python client libraries, over the last year and a half however we've seen a huge surge in adoption. This has been driven by the broad adoption of Supabase in the AI and ML community, many of whom are keen Pythonistas.
So today, we're announcing that the following Python Client Libraries are now officially supported on the Supabase platform:
- supabase-py
- auth-py
- storage-py
- functions-py
- realtime-py
supabase-py was originally started by maintainer lqmanh in September of 2020, and was shortly after joined by fedden and J0 (who went on to become a full time member of the Supabase Team). In recent years development has been driven by silentworks and juancarlospaco who have both been instrumental in the push to reaching feature parity with supabase-js.
Thank you so much to everyone who has contributed to the client libs so far and hopefully we'll see more community libs making the push for official support in the future.
Below is an overview of some recent features added to the collection of Python libs.
Enabled HTTP2 by default
Supabase clients will automatically use HTTP 2.0 when available by default, offering a seamless performance boost to your existing applications.
This improvement is implemented in a completely transparent way, and requires no changes to your existing code, while potentially delivering significant latency reduction and performance enhancements.
See also:
- https://github.com/supabase/functions-py/pull/115
- https://github.com/supabase/auth-py/pull/534
- https://github.com/supabase/postgrest-py/pull/462
- https://github.com/supabase/storage-py/pull/271
Follow redirects by default
Supabase clients now automatically follow all HTTP redirects by default, aligning with the behavior of Supabase clients in other programming languages.
This enhancement improves consistency across the ecosystem and simplifies the handling of redirects, reducing the need for manual intervention in common scenarios like URL changes or load balancing.
See also:
- https://github.com/supabase/postgrest-py/pull/449
- https://github.com/supabase/functions-py/pull/107
- https://github.com/supabase/storage-py/pull/257
- https://github.com/supabase/auth-py/pull/511
Keep-alive enabled by default
Supabase clients now automatically include a keep-alive HTTP header by default, that was sometimes missing, addressing this inconsistency in previous versions.
This enhancement optimizes connection management, potentially reducing latency, and improving performance by maintaining persistent connections with the server, especially beneficial for applications making very frequent API calls.
Edge Functions Regions
Added support for specifying the region that the edge function will run on (a region is basically a physical location in the world).
See also:
- https://github.com/supabase/functions-py/pull/126
Realtime V2
Realtime has been upgraded to version 2.0 with lots of improvements and fixes, including updated examples and the new Presence-related features (broadcast, subscribe, track, etc).
See also:
- https://github.com/supabase/realtime-py/pull/139
- https://github.com/supabase/realtime-py/pull/178
Auth improvements
Anonymous logins have been added to the Auth client, including a new is_anonymous boolean property that has been added to the class User, also sign_in_with_id_token() and sign_in_with_sso() methods have been added to the Auth Client, among a lot of other bug fixes.
See also:
- https://github.com/supabase/auth-py/pull/528
- https://github.com/supabase/auth-py/pull/548
- https://github.com/supabase/auth-py/pull/553
- https://github.com/supabase/auth-py/pull/506
Postgrest quoting/escaping in queries
Supabase improved PostgreSQL query safety by implementing sanitize_param() for parameter sanitization in internal SQL queries on the client-side, ensuring more secure data handling and query execution across all operations.
Running with unverified SSL
Some users need to run the Supabase clients with invalid or unverified SSL for whatever reason (SSL debuggers/tracers/profilers/etc in development environments), a new optional boolean argument was added to the constructors of the clients, then passing verify=False enables it to run with unverified SSL without warnings.
from postgrest import SyncPostgrestClient url: str = "https://example.com" h: dict = {"Custom-Header": "value"} with SyncPostgrestClient(url, schema="pub", headers=h, verify = False) as client: session = client.session assert session.base_url == "https://example.com"
See also:
- https://github.com/supabase/functions-py/pull/106
- https://github.com/supabase/storage-py/pull/256
- https://github.com/supabase/auth-py/pull/506
- https://github.com/supabase/postgrest-py/pull/448
- https://github.com/supabase/supabase-py/pull/813
Close socket in Realtime
The Supabase Realtime library now includes a new close() method for closing the socket connections.
This addition provides developers with finer control over the connection lifecycle, allowing explicit closing of the socket connections when needed.
import os from realtime import AsyncRealtimeClient def callback1(payload): print("Callback 1: ", payload) SUPABASE_ID: str = os.environ.get("SUPABASE_ID") API_KEY: str = os.environ.get("SUPABASE_KEY") URL: str = f"wss://{SUPABASE_ID}.supabase.co/realtime/v1/websocket" client = AsyncRealtimeClient(URL, API_KEY) await client.connect() channel_1 = s.channel("realtime:public:sample") channel_1.subscribe().on_postgres_changes("INSERT", callback1) await client.listen() await client.close()
See also:
- https://github.com/supabase-community/realtime-py/pull/142
Edge Functions timeouts
Timeouts for Edge Functions are now fixed and long-running functions finish correctly, there is no longer a library client-side internal timeout cutting off the functions.
Users can now confidently implement more complex operations in Edge Functions.
import os from supabase import create_client from supabase.lib.client_options import ClientOptions url: str = os.environ.get("SUPABASE_URL") key: str = os.environ.get("SUPABASE_KEY") options = ClientOptions(function_client_timeout = 15) client = create_client(url, key, options) client.functions.url = "http://127.0.0.1:54321/functions/v1/hello-world" print(client.functions.invoke("hello"))
See also:
- https://github.com/supabase/functions-py/pull/120
- https://github.com/supabase/supabase-py/pull/846
New tool Vec2pg to migrate data to Supabase
A new simple and extensible CLI tool to migrate vector data from other services and SASS into Supabase was created, it can migrate vector data from Pinecone and Qdrant into Supabase with a single command, streamlining workflows and enhancing data portability across AI and ML projects.
You can vote for other vector database providers to be added in the future!
See also:
- https://github.com/supabase-community/vec2pg
- https://github.com/supabase-community/vec2pg/pull/5
- https://github.com/supabase-community/vec2pg/issues/6
Updated CI
Continuous Integration builds for all the libraries have been upgraded and made more strict (linters, etc).
See also:
- https://github.com/supabase/supabase-py/pull/772
- https://github.com/supabase/supabase-py/pull/774
- https://github.com/supabase/functions-py/pull/93
- https://github.com/supabase/functions-py/pull/92
- https://github.com/supabase/storage-py/pull/240
- https://github.com/supabase/storage-py/pull/237
- https://github.com/supabase/realtime-py/pull/132
- https://github.com/supabase/realtime-py/pull/131
- https://github.com/supabase/postgrest-py/pull/424
- https://github.com/supabase/postgrest-py/pull/422
- https://github.com/supabase/functions-py/pull/139
- https://github.com/supabase/storage-py/pull/287
- https://github.com/supabase/auth-py/pull/572
- https://github.com/supabase/postgrest-py/pull/484
- https://github.com/supabase/supabase-py/pull/887
- https://github.com/supabase/realtime-py/pull/182
Miscellaneous
- Unittests coverage was improved across all code repositories.
- Cyclomatic complexity has been analyzed and improved in all the libraries (mccabe, prospector).
- Multiple fixes for code style, symbol naming, documentation, comments, and docstrings.
Contributing
If you'd like to get involved in contributing to our Python client libraries see here for some information on how to contribute, and check the list of open issues for some inspiration on what to work on.
Getting started
Full documentation is available for the Supabase Python Client libraries on the Supabase Docs site.
The above is the detailed content of Supabase Python. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

The key to dealing with API authentication is to understand and use the authentication method correctly. 1. APIKey is the simplest authentication method, usually placed in the request header or URL parameters; 2. BasicAuth uses username and password for Base64 encoding transmission, which is suitable for internal systems; 3. OAuth2 needs to obtain the token first through client_id and client_secret, and then bring the BearerToken in the request header; 4. In order to deal with the token expiration, the token management class can be encapsulated and automatically refreshed the token; in short, selecting the appropriate method according to the document and safely storing the key information is the key.

To test the API, you need to use Python's Requests library. The steps are to install the library, send requests, verify responses, set timeouts and retry. First, install the library through pipinstallrequests; then use requests.get() or requests.post() and other methods to send GET or POST requests; then check response.status_code and response.json() to ensure that the return result is in compliance with expectations; finally, add timeout parameters to set the timeout time, and combine the retrying library to achieve automatic retry to enhance stability.

To create modern and efficient APIs using Python, FastAPI is recommended; it is based on standard Python type prompts and can automatically generate documents, with excellent performance. After installing FastAPI and ASGI server uvicorn, you can write interface code. By defining routes, writing processing functions, and returning data, APIs can be quickly built. FastAPI supports a variety of HTTP methods and provides automatically generated SwaggerUI and ReDoc documentation systems. URL parameters can be captured through path definition, while query parameters can be implemented by setting default values for function parameters. The rational use of Pydantic models can help improve development efficiency and accuracy.

In Python, variables defined inside a function are local variables and are only valid within the function; externally defined are global variables that can be read anywhere. 1. Local variables are destroyed as the function is executed; 2. The function can access global variables but cannot be modified directly, so the global keyword is required; 3. If you want to modify outer function variables in nested functions, you need to use the nonlocal keyword; 4. Variables with the same name do not affect each other in different scopes; 5. Global must be declared when modifying global variables, otherwise UnboundLocalError error will be raised. Understanding these rules helps avoid bugs and write more reliable functions.

The way to access nested JSON objects in Python is to first clarify the structure and then index layer by layer. First, confirm the hierarchical relationship of JSON, such as a dictionary nested dictionary or list; then use dictionary keys and list index to access layer by layer, such as data "details"["zip"] to obtain zip encoding, data "details"[0] to obtain the first hobby; to avoid KeyError and IndexError, the default value can be set by the .get() method, or the encapsulation function safe_get can be used to achieve secure access; for complex structures, recursively search or use third-party libraries such as jmespath to handle.

Yes, you can parse HTML tables using Python and Pandas. First, use the pandas.read_html() function to extract the table, which can parse HTML elements in a web page or string into a DataFrame list; then, if the table has no clear column title, it can be fixed by specifying the header parameters or manually setting the .columns attribute; for complex pages, you can combine the requests library to obtain HTML content or use BeautifulSoup to locate specific tables; pay attention to common pitfalls such as JavaScript rendering, encoding problems, and multi-table recognition.

def is suitable for complex functions, supports multiple lines, document strings and nesting; lambda is suitable for simple anonymous functions and is often used in scenarios where functions are passed by parameters. The situation of selecting def: ① The function body has multiple lines; ② Document description is required; ③ Called multiple places. When choosing a lambda: ① One-time use; ② No name or document required; ③ Simple logic. Note that lambda delay binding variables may throw errors and do not support default parameters, generators, or asynchronous. In actual applications, flexibly choose according to needs and give priority to clarity.

How to efficiently handle large JSON files in Python? 1. Use the ijson library to stream and avoid memory overflow through item-by-item parsing; 2. If it is in JSONLines format, you can read it line by line and process it with json.loads(); 3. Or split the large file into small pieces and then process it separately. These methods effectively solve the memory limitation problem and are suitable for different scenarios.
