Skip to main content

Python Client Library for GoTrue

Project description

gotrue-py

License: MIT CI Python Version Codecov Last commit GitHub commit activity Github Stars Github Forks Github Watchers GitHub contributors

This is a Python port of the supabase js gotrue client. 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.

Installation

We are still working on making the gotrue 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.

Also, the gotrue library for Python parses the date-time string into datetime Python objects. The JS client keeps the date-time as strings.

Usage (outdated)

Important: This section is outdated, you can be guided by the JS client documentation because this Python client has a lot of parity with the JS client.

To instantiate 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

Contributions

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

  • Add documentation
  • Update README.md

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.3.3.tar.gz (20.9 kB view details)

Uploaded Source

Built Distribution

gotrue-0.3.3-py3-none-any.whl (23.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: gotrue-0.3.3.tar.gz
  • Upload date:
  • Size: 20.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.2.0 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.0

File hashes

Hashes for gotrue-0.3.3.tar.gz
Algorithm Hash digest
SHA256 284260bfd152b89b519ea7db64579ddea47a6c1ddfc5d24ab50eed0ae980209d
MD5 545fae6a4b323462e2cfeb5e33e50c41
BLAKE2b-256 043da99ce12c2c91c6b4652341511a3dcfdf2f5e386c2156795cd89ea4431bcb

See more details on using hashes here.

File details

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

File metadata

  • Download URL: gotrue-0.3.3-py3-none-any.whl
  • Upload date:
  • Size: 23.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.2.0 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.0

File hashes

Hashes for gotrue-0.3.3-py3-none-any.whl
Algorithm Hash digest
SHA256 d38d8d36f1d0a4927f3fedaac265982e406757fb5767073d5a2a55b23a099223
MD5 2976441965449b4c0384cbd28d358609
BLAKE2b-256 0a87cc7f8f2c6dfca5d09b90004e5ea6fb919bccfaa591f775d799df552e9aed

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