The `realtime` library is the official Python client for Supabase Realtime, offering capabilities for real-time communication. It allows applications to send and receive ephemeral messages via Broadcast, track and synchronize shared state with Presence, and listen for database changes using Postgres Change Data Capture (CDC). The current version is 2.28.3, and it receives frequent updates as part of the broader Supabase ecosystem.
pip install realtimeVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to establish a connection to the Supabase Realtime server, subscribe to a channel, listen for PostgreSQL database changes, and receive broadcast messages. Remember to replace placeholder `REALTIME_URL` and `SUPABASE_ANON_KEY` with your actual Supabase project details, typically retrieved from your project settings. Ensure your API key has the necessary permissions (e.g., 'anon' key for public read access or a 'service_role' key for elevated privileges).
Verify the `REALTIME_URL` against your Supabase project's Realtime connection string in the Supabase Dashboard, or the local Supabase CLI output.
Update your code to access the change data using `payload['event']` instead of `payload['events']`. This change was noted in `supabase-py`'s v2.27.1 release, which the `realtime` client aligns with.
Implement robust error handling and reconnection logic. Ensure your `API_KEY` is valid and has the necessary JWT claims (e.g., `exp` and `role`). Monitor network conditions and Supabase service status. Review GitHub issues for known transient problems.
Upgrade your project to Python 3.10 or newer. Regularly check the `realtime` PyPI page or GitHub repository for updated Python version requirements.
When generating or using JWTs, ensure they are correctly signed, unexpired, and contain the appropriate `role` claim that matches your Row Level Security (RLS) policies in Supabase.