Giter Site home page Giter Site logo

jantznick / gotrue-py Goto Github PK

View Code? Open in Web Editor NEW

This project forked from supabase-community/auth-py

0.0 0.0 0.0 1.24 MB

Python client implementation of Supabase's GoTrue

License: MIT License

Python 97.82% Makefile 0.30% PLpgSQL 1.32% Dockerfile 0.57%

gotrue-py's Introduction

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 SyncGoTrueClient

headers = {
    "apiKey": "my-mega-awesome-api-key",
    # ... any other headers you might need.
}
client: SyncGoTrueClient = SyncGoTrueClient(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="[email protected]")

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

user: Dict[str, Any] = client.sign_up(email="[email protected]", 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:

gotrue-py's People

Contributors

leynier avatar dependabot[bot] avatar j0 avatar fedden avatar dreinon avatar yuvanist avatar bariqhibat avatar actions-user avatar sourcery-ai[bot] avatar olirice avatar jantznick avatar lmoj avatar hgseo16 avatar lawrencecchen avatar zodman avatar connorlurring avatar songololo avatar github-actions[bot] avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.