Skip to main content

Python Client Library for GoTrue

Project description

Gotrue-py

This is a Python port of the supabase js gotrue client. The current status is that there is not complete feature pairity when compared with the js-client, but this something we are working on.

Installation

We are still working on making the go-true python library more user-friendly. For now here are some sparse notes on how to install the module

Poetry

poetry add gotrue

Pip

pip install gotrue

Differences to the JS client

It should be noted there are differences to the JS client. 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.

Firstly, feature pairity is not 100% with the JS client. In most cases we match the methods and attributes of the JS client and api classes, but is some places (e.g for browser specific code) it didn't make sense to port the code line for line.

There is also a divergence in terms of how errors are raised. In the JS client, the errors are returned as part of the object, which the user can choose to process in whatever way they see fit. In this Python client, we raise the errors directly where they originate, as it was felt this was more Pythonic and adhered to the idioms of the language more directly.

In JS we return the error, but in Python we just raise it.

const { data, error } = client.sign_up(...)

The other key difference is we do not use pascalCase to encode variable and method names. Instead we use the snake_case convention adopted in the Python language.

Usage

To instanciate the client, you'll need the URL and any request headers at a minimum.

from gotrue import Client

headers = {
    "apiKey": "my-mega-awesome-api-key",
    # ... any other headers you might need.
}
client: Client = Client(url="www.genericauthwebsite.com", headers=headers)

To send a magic email link to the user, just provide the email kwarg to the sign_in method:

user: Dict[str, Any] = client.sign_up(email="example@gmail.com")

To login with email and password, provide both to the sign_in method:

user: Dict[str, Any] = client.sign_up(email="example@gmail.com", password="*********")

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.

client.sign_out()
assert client.user() is None
assert client.session() is None

We can refesh a users session.

# The user should already be signed in at this stage.
user = client.refresh_session()
assert client.user() is not None
assert client.session() is not None

Tests

At the moment we use a pre-defined supabase instance to test the functionality. This may change over time. You can run the tests like so:

SUPABASE_TEST_KEY="eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJyb2xlIjoiYW5vbiIsImlhdCI6MTYxMjYwOTMyMiwiZXhwIjoxOTI4MTg1MzIyfQ.XL9W5I_VRQ4iyQHVQmjG0BkwRfx6eVyYB3uAKcesukg" \
SUPABASE_TEST_URL="https://tfsatoopsijgjhrqplra.supabase.co" \
pytest -sx

Contributions

We would be immensely grateful for any contributions to this project. In particular are the following items:

  • Figure out to use either Sessions to manage headers or allow passing in of headers
  • Add documentation.
  • Add more tests.
  • Ensuring feature-parity with the js-client.
  • Supporting 3rd party provider authentication.
  • Implement a js port of setTimeout for the refresh session code.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gotrue-0.2.0.tar.gz (7.5 kB view details)

Uploaded Source

Built Distribution

gotrue-0.2.0-py3-none-any.whl (8.9 kB view details)

Uploaded Python 3

File details

Details for the file gotrue-0.2.0.tar.gz.

File metadata

  • Download URL: gotrue-0.2.0.tar.gz
  • Upload date:
  • Size: 7.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.55.1 CPython/3.7.4

File hashes

Hashes for gotrue-0.2.0.tar.gz
Algorithm Hash digest
SHA256 de6bb752fcc6d5b59eadf44a0d39644203407e6905701c30c00dea3747273e4a
MD5 1089746d6f8e14ff29535ae69d4202a8
BLAKE2b-256 e158488dcf5bb223358b0918a1fda4d5edd1ed42d47e92b89319f7da7390d27d

See more details on using hashes here.

File details

Details for the file gotrue-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: gotrue-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 8.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.55.1 CPython/3.7.4

File hashes

Hashes for gotrue-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e0260c096f83f89c5599754d0ec71f52cb7073539f95aca3d772ad50c78dd34a
MD5 8cc66e2f43a4a03cc51a8ab7cc3c4467
BLAKE2b-256 311e66231da527b2d4f8f31d00de2aa58db8b68c9fc246dc14a11dc38d22d463

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page