mirror of
https://github.com/supabase/supabase.git
synced 2026-12-04 07:29:16 +00:00
Closes DOCS-1616 ## Problem The remaining quickstarts don't follow the [quickstart template](https://github.com/supabase/supabase/blob/docs/quickstart-template/apps/docs/style-guide/templates/quickstart.md) either. ## Solution - **Heading IDs:** each numbered step ends with the template's ID, such as `[#create-the-client]`. - **Heading wording:** eight headings now use the template's wording, such as `Create the Supabase client`. - **Style:** the prose follows the word list and elements rules. **Not changed:** RedwoodJS, Spring Boot, and Refine. DOCS-1624 covers them. **Before and after:** numbered headings that use the template's wording. | Page | Before | After | | --- | --- | --- | | iOS | 5/8 | 6/8 | | Kotlin | 4/8 | 5/8 | | Flask, Flutter, Unity | 5/7 | 6/7 | | Expo | 6/7 | 7/7 | | Reflex | 7/7 | 7/7 | | Laravel | 3/7 | 3/7 | | Rails | 3/6 | 3/6 | **Possible errors, not changed:** - The iOS page opens **Xcode > New Project > iOS > App**. Xcode's menu might be **File > New > Project**. - The Vue page says to drop a type import that `supabaseClient.ts` doesn't have. ## Preview links | Page | Preview | | --- | --- | | Flask | [Preview](https://docs-git-docs-quickstart-rework-other-supabase.vercel.app/docs/guides/getting-started/quickstarts/flask) | | Reflex | [Preview](https://docs-git-docs-quickstart-rework-other-supabase.vercel.app/docs/guides/getting-started/quickstarts/reflex) | | Expo React Native | [Preview](https://docs-git-docs-quickstart-rework-other-supabase.vercel.app/docs/guides/getting-started/quickstarts/expo-react-native) | | Flutter | [Preview](https://docs-git-docs-quickstart-rework-other-supabase.vercel.app/docs/guides/getting-started/quickstarts/flutter) | | iOS SwiftUI | [Preview](https://docs-git-docs-quickstart-rework-other-supabase.vercel.app/docs/guides/getting-started/quickstarts/ios-swiftui) | | Kotlin | [Preview](https://docs-git-docs-quickstart-rework-other-supabase.vercel.app/docs/guides/getting-started/quickstarts/kotlin) | | Unity | [Preview](https://docs-git-docs-quickstart-rework-other-supabase.vercel.app/docs/guides/getting-started/quickstarts/unity) | | Laravel | [Preview](https://docs-git-docs-quickstart-rework-other-supabase.vercel.app/docs/guides/getting-started/quickstarts/laravel) | | Ruby on Rails | [Preview](https://docs-git-docs-quickstart-rework-other-supabase.vercel.app/docs/guides/getting-started/quickstarts/ruby-on-rails) | ## Review category (docs PRs only) <!-- If this PR changes docs and you're on the Supabase team, select one category. PRs from forks are always reviewed as Low, so you can skip this section. --> - [ ] Critical: needs a review as soon as possible - [ ] Urgent: the feature ships soon, or it's blocking something else - [ ] Moderate: good to have soon, not urgent - [ ] Low: get to it when you can ## Review instructions 1. Open the [Kotlin preview](https://docs-git-docs-quickstart-rework-other-supabase.vercel.app/docs/guides/getting-started/quickstarts/kotlin) and click **Create the Supabase client** in the table of contents. The URL ends in `#create-the-client`. 2. Open the [Laravel preview](https://docs-git-docs-quickstart-rework-other-supabase.vercel.app/docs/guides/getting-started/quickstarts/laravel) and click the **Run the database migrations** link in step 4. The page scrolls to step 7. ## Checklist Check all before review: - [ ] I have read [CONTRIBUTING.md](https://github.com/supabase/supabase/blob/master/CONTRIBUTING.md) - [ ] If I wrote a new docs topic or edited an existing topic, I used the `/write-the-docs` or `/edit-the-docs` skill, which applies the docs [style guide](https://github.com/supabase/supabase/tree/master/apps/docs/style-guide)
133 lines
3.9 KiB
Plaintext
133 lines
3.9 KiB
Plaintext
---
|
|
title: 'Use Supabase with Reflex'
|
|
subtitle: 'Learn how to create a Supabase project, add some sample data to your database, and query the data from a Reflex app.'
|
|
breadcrumb: 'Framework Quickstarts'
|
|
---
|
|
|
|
<AiPrompt id="reflex" />
|
|
|
|
<$Partial path="quickstart_db_setup.mdx" />
|
|
|
|
## 3. Create a Reflex app [#create-an-app]
|
|
|
|
Create a directory for your Reflex app, initialize a project with `uv`, add Reflex as a dependency, and scaffold a blank app with `--template blank`.
|
|
|
|
```bash
|
|
mkdir my_app && cd my_app
|
|
uv init
|
|
uv add reflex
|
|
uv run reflex init --template blank
|
|
```
|
|
|
|
## 4. Set up AI tooling (optional) [#set-up-ai-tooling]
|
|
|
|
<$Partial path="quickstart_ai_tooling.mdx" />
|
|
|
|
## 5. Install the Supabase client library [#install-the-client-library]
|
|
|
|
Use the `supabase-py` client library to query and update your Supabase data from a Reflex app.
|
|
|
|
Install `supabase-py` and `python-dotenv`, which loads environment variables.
|
|
|
|
```bash
|
|
uv add supabase python-dotenv
|
|
```
|
|
|
|
## 6. Declare Supabase environment variables [#declare-environment-variables]
|
|
|
|
Create a `.env` file in your project root and add your Supabase connection variables. Get them from the following helper, or from the project [**Connect** panel](/dashboard/project/_?showConnect=true&connectTab=frameworks):
|
|
|
|
<Button variant="primary" asChild>
|
|
<a href="/dashboard/project/_?showConnect=true&connectTab=frameworks">Open Connect panel</a>
|
|
</Button>
|
|
|
|
```dotenv name=.env
|
|
SUPABASE_URL=<SUBSTITUTE_SUPABASE_URL>
|
|
SUPABASE_PUBLISHABLE_KEY=<SUBSTITUTE_SUPABASE_PUBLISHABLE_KEY>
|
|
```
|
|
|
|
<$Partial path="api_settings.mdx" variables={{ "framework": "", "tab": "" }} />
|
|
|
|
## 7. Create the Supabase client [#create-the-client]
|
|
|
|
Open `my_app/my_app.py` and add the following code to create an async Supabase client from your environment variables. Reflex's event handlers run inside an async event loop, so the code creates the client once with `acreate_client` and reuses it across requests.
|
|
|
|
```python name=my_app/my_app.py
|
|
import os
|
|
import reflex as rx
|
|
from supabase import acreate_client, AsyncClient
|
|
from dotenv import load_dotenv
|
|
|
|
load_dotenv()
|
|
|
|
_supabase: AsyncClient | None = None
|
|
|
|
|
|
async def get_supabase() -> AsyncClient:
|
|
global _supabase
|
|
if _supabase is None:
|
|
_supabase = await acreate_client(
|
|
os.environ.get("SUPABASE_URL"),
|
|
os.environ.get("SUPABASE_PUBLISHABLE_KEY"),
|
|
)
|
|
return _supabase
|
|
```
|
|
|
|
## 8. Query data from the app [#query-data]
|
|
|
|
Add a `State` class that holds the query result and an async event handler that fetches data from your `instruments` table. Then add a page that renders the result. `on_load` triggers the handler when the page opens.
|
|
|
|
```python name=my_app/my_app.py
|
|
from postgrest import APIError
|
|
|
|
|
|
class State(rx.State):
|
|
instruments: list[dict] = []
|
|
error: str = ""
|
|
|
|
async def load_instruments(self):
|
|
supabase = await get_supabase()
|
|
try:
|
|
response = await supabase.table("instruments").select("*").execute()
|
|
except APIError as error:
|
|
self.error = f"Error loading instruments: {error.message}"
|
|
return
|
|
self.instruments = response.data
|
|
|
|
|
|
def index() -> rx.Component:
|
|
return rx.container(
|
|
rx.heading("Instruments"),
|
|
rx.cond(
|
|
State.error,
|
|
rx.text(State.error),
|
|
rx.foreach(
|
|
State.instruments,
|
|
lambda instrument: rx.text(instrument["name"]),
|
|
),
|
|
),
|
|
)
|
|
|
|
|
|
app = rx.App()
|
|
app.add_page(index, on_load=State.load_instruments)
|
|
```
|
|
|
|
## 9. Start the app [#start-the-app]
|
|
|
|
Run the Reflex development server and go to `http://localhost:3000` in a browser. The page lists the instruments.
|
|
|
|
```bash
|
|
uv run reflex run
|
|
```
|
|
|
|
<$Partial path="quickstart_going_to_production.mdx" />
|
|
|
|
## Next steps
|
|
|
|
Build on this app with the following resources:
|
|
|
|
- Set up [Auth](/docs/guides/auth) for your app
|
|
- [Insert more data](/docs/guides/database/import-data) into your database
|
|
- Upload and serve static files using [Storage](/docs/guides/storage)
|