This repository was archived by the owner on Sep 8, 2025. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 53
Bring closer to pairity with supabase/gotrue-js #1
Merged
Merged
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
e753927
bringing closer to pairity with gotrue js
fedden 645136a
add contstants
fedden 1a3bef2
sort typos
fedden 93f984b
rm crap
fedden d620032
add gitignoire
fedden 29e35ed
wrap up response cleanly into a dict for users
fedden 8b3dc48
updates to get tests passing
fedden c970dfe
add for working tests
fedden 4808a34
cleanup tests etc
fedden 3309684
add some basic documentation in README
fedden 44fc9da
link to js-client
fedden 7dea900
hopefully ensure the test ci works
fedden 2b74646
document the tests
fedden 337746c
ensuring tests pass
fedden 94470db
add another todo
fedden a7be2da
updating the pyproject.toml
fedden 7cdf326
enable simple install that works for non-poetry envs
fedden 68ed44b
correct version
fedden 1828117
Update gotrue/api.py
fedden f0e77aa
Update gotrue/api.py
fedden 289b184
Update gotrue/client.py
fedden 3ad5781
add return statements in documentation
fedden 608c2b1
remove env vars
fedden File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,162 @@ | ||
| .mypy_cache/ | ||
| __pycache__/ | ||
| tags | ||
|
|
||
| # Swap | ||
| [._]*.s[a-v][a-z] | ||
| !*.svg # comment out if you don't need vector files | ||
| [._]*.sw[a-p] | ||
| [._]s[a-rt-v][a-z] | ||
| [._]ss[a-gi-z] | ||
| [._]sw[a-p] | ||
|
|
||
| # Session | ||
| Session.vim | ||
| Sessionx.vim | ||
|
|
||
| # Temporary | ||
| .netrwhist | ||
| *~ | ||
| # Auto-generated tag files | ||
| tags | ||
| # Persistent undo | ||
| [._]*.un~ | ||
|
|
||
| # Byte-compiled / optimized / DLL files | ||
| __pycache__/ | ||
| *.py[cod] | ||
| *$py.class | ||
|
|
||
| # C extensions | ||
| *.so | ||
|
|
||
| # Distribution / packaging | ||
| .Python | ||
| build/ | ||
| develop-eggs/ | ||
| dist/ | ||
| downloads/ | ||
| eggs/ | ||
| .eggs/ | ||
| lib/ | ||
| lib64/ | ||
| parts/ | ||
| sdist/ | ||
| var/ | ||
| wheels/ | ||
| share/python-wheels/ | ||
| *.egg-info/ | ||
| .installed.cfg | ||
| *.egg | ||
| MANIFEST | ||
|
|
||
| # PyInstaller | ||
| # Usually these files are written by a python script from a template | ||
| # before PyInstaller builds the exe, so as to inject date/other infos into it. | ||
| *.manifest | ||
| *.spec | ||
|
|
||
| # Installer logs | ||
| pip-log.txt | ||
| pip-delete-this-directory.txt | ||
|
|
||
| # Unit test / coverage reports | ||
| htmlcov/ | ||
| .tox/ | ||
| .nox/ | ||
| .coverage | ||
| .coverage.* | ||
| .cache | ||
| nosetests.xml | ||
| coverage.xml | ||
| *.cover | ||
| *.py,cover | ||
| .hypothesis/ | ||
| .pytest_cache/ | ||
| cover/ | ||
|
|
||
| # Translations | ||
| *.mo | ||
| *.pot | ||
|
|
||
| # Django stuff: | ||
| *.log | ||
| local_settings.py | ||
| db.sqlite3 | ||
| db.sqlite3-journal | ||
|
|
||
| # Flask stuff: | ||
| instance/ | ||
| .webassets-cache | ||
|
|
||
| # Scrapy stuff: | ||
| .scrapy | ||
|
|
||
| # Sphinx documentation | ||
| docs/_build/ | ||
|
|
||
| # PyBuilder | ||
| .pybuilder/ | ||
| target/ | ||
|
|
||
| # Jupyter Notebook | ||
| .ipynb_checkpoints | ||
|
|
||
| # IPython | ||
| profile_default/ | ||
| ipython_config.py | ||
|
|
||
| # pyenv | ||
| # For a library or package, you might want to ignore these files since the code is | ||
| # intended to run in multiple environments; otherwise, check them in: | ||
| # .python-version | ||
|
|
||
| # pipenv | ||
| # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. | ||
| # However, in case of collaboration, if having platform-specific dependencies or dependencies | ||
| # having no cross-platform support, pipenv may install dependencies that don't work, or not | ||
| # install all needed dependencies. | ||
| #Pipfile.lock | ||
|
|
||
| # PEP 582; used by e.g. github.com/David-OConnor/pyflow | ||
| __pypackages__/ | ||
|
|
||
| # Celery stuff | ||
| celerybeat-schedule | ||
| celerybeat.pid | ||
|
|
||
| # SageMath parsed files | ||
| *.sage.py | ||
|
|
||
| # Environments | ||
| .env | ||
| .venv | ||
| env/ | ||
| venv/ | ||
| ENV/ | ||
| env.bak/ | ||
| venv.bak/ | ||
|
|
||
| # Spyder project settings | ||
| .spyderproject | ||
| .spyproject | ||
|
|
||
| # Rope project settings | ||
| .ropeproject | ||
|
|
||
| # mkdocs documentation | ||
| /site | ||
|
|
||
| # mypy | ||
| .mypy_cache/ | ||
| .dmypy.json | ||
| dmypy.json | ||
|
|
||
| # Pyre type checker | ||
| .pyre/ | ||
|
|
||
| # pytype static type analyzer | ||
| .pytype/ | ||
|
|
||
| # Cython debug symbols | ||
| cython_debug/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,33 +1,84 @@ | ||
|
|
||
| # Gotrue-py | ||
|
|
||
| ## Status: POC | ||
| This is a hacky `gotrue-py` client conceived during a very draggy class. It was developed against the [supabase](https://github.com/supabase/gotrue) fork of netlify's gotrue. The design mirrors that of [GoTrue-elixir](https://github.com/joshnuss/gotrue-elixir) | ||
| This is a Python port of the [supabase js gotrue client](https://github.com/supabase/gotrue-js/). 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 | ||
| ```bash | ||
| poetry add gotrue | ||
| ``` | ||
|
|
||
| Here's how you'd install the library with gotrue | ||
| ### With Poetry | ||
| ### Pip | ||
| ```bash | ||
| pip install gotrue | ||
| ``` | ||
|
|
||
| `poetry add gotrue` | ||
| ## Differences to the JS client | ||
| 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. | ||
|
|
||
| ### With pip | ||
| `pip3 install gotrue` | ||
| Firstly, feature pairity is not 100% with the [JS client](https://github.com/supabase/gotrue-js/). In most cases we match the methods and attributes of the [JS client](https://github.com/supabase/gotrue-js/) 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](https://github.com/supabase/gotrue-js/), 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. | ||
|
|
||
| ### Usage | ||
| In JS we return the error, but in Python we just raise it. | ||
| ```js | ||
| const { data, error } = client.sign_up(...) | ||
| ``` | ||
| import gotrue | ||
|
|
||
| client = gotrue.Client("www.genericauthwebsite.com") | ||
| credentials = {"email": "anemail@gmail.com", "password": "gmebbnok"} | ||
| client.sign_up(credentials) | ||
| client.sign_in(credentials) | ||
| 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. | ||
| ```python | ||
| 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: | ||
| ```python | ||
| user: Dict[str, Any] = client.sign_up(email="example@gmail.com") | ||
| ``` | ||
|
|
||
| To login with email and password, provide both to the `sign_in` method: | ||
| ```python | ||
| 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. | ||
| ```python | ||
| client.sign_out() | ||
| assert client.user() is None | ||
| assert client.session() is None | ||
| ``` | ||
|
|
||
| We can refesh a users session. | ||
| ```python | ||
| # 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: | ||
| ```bash | ||
| SUPABASE_TEST_KEY="eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJyb2xlIjoiYW5vbiIsImlhdCI6MTYxMjYwOTMyMiwiZXhwIjoxOTI4MTg1MzIyfQ.XL9W5I_VRQ4iyQHVQmjG0BkwRfx6eVyYB3uAKcesukg" \ | ||
| SUPABASE_TEST_URL="https://tfsatoopsijgjhrqplra.supabase.co" \ | ||
| pytest -sx | ||
| ``` | ||
|
|
||
| ### Development/TODOs | ||
| - Figure out to use either Sessions to manage headers or allow passing in of headers | ||
| - [] Add Documentation | ||
| ## Contributions | ||
| We would be immensely grateful for any contributions to this project. In particular are the following items: | ||
fedden marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| - [x] 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. | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,6 @@ | ||
| __version__ = '0.1.0' | ||
| __version__ = '0.2.0' | ||
|
|
||
| from . import lib | ||
| from . import api | ||
| from . import client | ||
| from .client import Client |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.