Skip to content

Commit 0c7f89c

Browse files
author
Guilherme Souza
authored
chore: update README and fix coverage badge (supabase#697)
1 parent 2b179e3 commit 0c7f89c

File tree

1 file changed

+91
-30
lines changed

1 file changed

+91
-30
lines changed

README.md

Lines changed: 91 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,15 @@
11
# Auth-py
22

3-
[![License: MIT](https://img.shields.io/badge/License-MIT-green.svg?label=license)](https://opensource.org/licenses/MIT)
43
[![CI](https://github.com/supabase-community/gotrue-py/actions/workflows/ci.yml/badge.svg)](https://github.com/supabase-community/gotrue-py/actions/workflows/ci.yml)
54
[![Python](https://img.shields.io/pypi/pyversions/gotrue)](https://pypi.org/project/gotrue)
65
[![Version](https://img.shields.io/pypi/v/gotrue?color=%2334D058)](https://pypi.org/project/gotrue)
7-
[![Codecov](https://codecov.io/gh/supabase-community/gotrue-py/branch/main/graph/badge.svg)](https://codecov.io/gh/supabase-community/gotrue-py)
8-
[![Last commit](https://img.shields.io/github/last-commit/supabase-community/gotrue-py.svg?style=flat)](https://github.com/supabase-community/gotrue-py/commits)
9-
[![GitHub commit activity](https://img.shields.io/github/commit-activity/m/supabase-community/gotrue-py)](https://github.com/supabase-community/gotrue-py/commits)
10-
[![Github Stars](https://img.shields.io/github/stars/supabase-community/gotrue-py?style=flat&logo=github)](https://github.com/supabase-community/gotrue-py/stargazers)
11-
[![Github Forks](https://img.shields.io/github/forks/supabase-community/gotrue-py?style=flat&logo=github)](https://github.com/supabase-community/gotrue-py/network/members)
12-
[![Github Watchers](https://img.shields.io/github/watchers/supabase-community/gotrue-py?style=flat&logo=github)](https://github.com/supabase-community/gotrue-py)
13-
[![GitHub contributors](https://img.shields.io/github/contributors/supabase-community/gotrue-py)](https://github.com/supabase-community/gotrue-py/graphs/contributors)
6+
[![Coverage Status](https://coveralls.io/repos/github/supabase/auth-py/badge.svg?branch=main)](https://coveralls.io/github/supabase/auth-py?branch=main)
147

158
This is a Python port of the [supabase js gotrue client](https://github.com/supabase/gotrue-js). The current state is that there is a features parity but with small differences that are mentioned in the section **Differences to the JS client**. As of December 14th, we renamed to repo from `gotrue-py` to `auth-py` to mirror the changes in the JavaScript library.
169

1710
## Installation
1811

19-
We are still working on making the `supabase_auth` python library more user-friendly. For now here are some sparse notes on how to install the module.
12+
The package can be installed using pip or poetry:
2013

2114
### Poetry
2215

@@ -30,6 +23,19 @@ poetry add supabase_auth
3023
pip install supabase_auth
3124
```
3225

26+
## Features
27+
28+
- Full feature parity with the JavaScript client
29+
- Support for both synchronous and asynchronous operations
30+
- MFA (Multi-Factor Authentication) support
31+
- OAuth and SSO integration
32+
- Magic link and OTP authentication
33+
- Phone number authentication
34+
- Anonymous sign-in
35+
- Session management with auto-refresh
36+
- JWT token handling and verification
37+
- User management and profile updates
38+
3339
## Differences to the JS client
3440

3541
It should be noted there are differences to the [JS client](https://github.com/supabase/gotrue-js). If you feel particulaly strongly about them and want to motivate a change, feel free to make a GitHub issue and we can discuss it there.
@@ -48,11 +54,11 @@ The other key difference is we do not use pascalCase to encode variable and meth
4854

4955
Also, the `supabase_auth` library for Python parses the date-time string into `datetime` Python objects. The [JS client](https://github.com/supabase/gotrue-js) keeps the date-time as strings.
5056

51-
## Usage (outdated)
57+
## Usage
5258

53-
**Important:** This section is outdated, you can be guided by the [JS client documentation](https://supabase.github.io/gotrue-js) because this Python client has a lot of parity with the JS client.
59+
The library provides both synchronous and asynchronous clients. Here are some examples:
5460

55-
To instantiate the client, you'll need the URL and any request headers at a minimum.
61+
### Synchronous Client
5662

5763
```python
5864
from supabase_auth import SyncGoTrueClient
@@ -62,37 +68,92 @@ headers = {
6268
# ... any other headers you might need.
6369
}
6470
client: SyncGoTrueClient = SyncGoTrueClient(url="www.genericauthwebsite.com", headers=headers)
65-
```
6671

67-
To send a magic email link to the user, just provide the email kwarg to the `sign_in` method:
72+
# Sign up with email and password
73+
user = client.sign_up(email="[email protected]", password="*********")
6874

69-
```python
70-
user: Dict[str, Any] = client.sign_up(email="[email protected]")
71-
```
75+
# Sign in with email and password
76+
user = client.sign_in_with_password(email="[email protected]", password="*********")
7277

73-
To login with email and password, provide both to the `sign_in` method:
78+
# Sign in with magic link
79+
user = client.sign_in_with_otp(email="[email protected]")
7480

75-
```python
76-
user: Dict[str, Any] = client.sign_up(email="[email protected]", password="*********")
81+
# Sign in with phone number
82+
user = client.sign_in_with_otp(phone="+1234567890")
83+
84+
# Sign in with OAuth
85+
user = client.sign_in_with_oauth(provider="google")
86+
87+
# Sign out
88+
client.sign_out()
89+
90+
# Get current user
91+
user = client.get_user()
92+
93+
# Update user profile
94+
user = client.update_user({"data": {"name": "John Doe"}})
7795
```
7896

79-
To sign out of the logged in user, call the `sign_out` method. We can then assert that the session and user are null values.
97+
### Asynchronous Client
8098

8199
```python
82-
client.sign_out()
83-
assert client.user() is None
84-
assert client.session() is None
100+
from supabase_auth import AsyncGoTrueClient
101+
102+
headers = {
103+
"apiKey": "my-mega-awesome-api-key",
104+
# ... any other headers you might need.
105+
}
106+
client: AsyncGoTrueClient = AsyncGoTrueClient(url="www.genericauthwebsite.com", headers=headers)
107+
108+
async def main():
109+
# Sign up with email and password
110+
user = await client.sign_up(email="[email protected]", password="*********")
111+
112+
# Sign in with email and password
113+
user = await client.sign_in_with_password(email="[email protected]", password="*********")
114+
115+
# Sign in with magic link
116+
user = await client.sign_in_with_otp(email="[email protected]")
117+
118+
# Sign in with phone number
119+
user = await client.sign_in_with_otp(phone="+1234567890")
120+
121+
# Sign in with OAuth
122+
user = await client.sign_in_with_oauth(provider="google")
123+
124+
# Sign out
125+
await client.sign_out()
126+
127+
# Get current user
128+
user = await client.get_user()
129+
130+
# Update user profile
131+
user = await client.update_user({"data": {"name": "John Doe"}})
132+
133+
# Run the async code
134+
import asyncio
135+
asyncio.run(main())
85136
```
86137

87-
We can refesh a users session.
138+
### MFA Support
139+
140+
The library includes support for Multi-Factor Authentication:
88141

89142
```python
90-
# The user should already be signed in at this stage.
91-
user = client.refresh_session()
92-
assert client.user() is not None
93-
assert client.session() is not None
143+
# List MFA factors
144+
factors = client.mfa.list_factors()
145+
146+
# Enroll a new MFA factor
147+
enrolled_factor = client.mfa.enroll({"factor_type": "totp"})
148+
149+
# Challenge and verify MFA
150+
challenge = client.mfa.challenge({"factor_id": "factor_id"})
151+
verified = client.mfa.verify({"factor_id": "factor_id", "code": "123456"})
152+
153+
# Unenroll a factor
154+
client.mfa.unenroll({"factor_id": "factor_id"})
94155
```
95156

96157
## Contributions
97158

98-
We would be immensely grateful for any contributions to this project.
159+
We would be immensely grateful for any contributions to this project.

0 commit comments

Comments
 (0)