{"id":28028406,"url":"https://github.com/permitio/permit-hasura-python-example","last_synced_at":"2025-05-11T07:13:36.180Z","repository":{"id":39903784,"uuid":"494057887","full_name":"permitio/permit-hasura-python-example","owner":"permitio","description":"A simple example demoing how to use Permit.io alongside Hasura.io","archived":false,"fork":false,"pushed_at":"2025-01-09T11:18:14.000Z","size":31,"stargazers_count":3,"open_issues_count":7,"forks_count":3,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-05-11T07:13:30.810Z","etag":null,"topics":["example","graphql","hasura","permit","python"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/permitio.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-05-19T12:15:53.000Z","updated_at":"2025-03-13T15:15:06.000Z","dependencies_parsed_at":"2025-01-10T08:03:49.065Z","dependency_job_id":null,"html_url":"https://github.com/permitio/permit-hasura-python-example","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/permitio%2Fpermit-hasura-python-example","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/permitio%2Fpermit-hasura-python-example/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/permitio%2Fpermit-hasura-python-example/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/permitio%2Fpermit-hasura-python-example/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/permitio","download_url":"https://codeload.github.com/permitio/permit-hasura-python-example/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253528978,"owners_count":21922637,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["example","graphql","hasura","permit","python"],"created_at":"2025-05-11T07:13:35.577Z","updated_at":"2025-05-11T07:13:36.175Z","avatar_url":"https://github.com/permitio.png","language":"Python","readme":"# Permit-Hasura Python example\n\nBuilds on the [Hasura Python example](https://hasura.io/docs/latest/graphql/core/actions/codegen/python-flask/) adding application level permission checks with Permit.\n\nThis example assumes an additional text field on the `user` table (mentioned in the Hasura example): `animal`\n\n## Setup and Run\n\n- Follow in the instructions in [Hasura Python example](https://hasura.io/docs/latest/graphql/core/actions/codegen/python-flask/) to setup your Hasura actions and underlying table.\n- Setup your [Permit account](https://app.permit.io) and [PDP](https://docs.permit.io/tutorials/quickstart)\n- Update secrets for Permit and Hasura in app.py constants\n- Install requirements : `pip install -r requirements.txt`\n- Use the code provided in app.py as the final result\n- run the app : `python app.py`\n- [Optional] Test the app with the util.py client : `python util.py`\n  - create a user `python util.py create-user \"user@test.com\" \"Pass123\"`\n  - login and list animals as user `python util.py list-animals \"user@test.com\" \"Pass123\"`\n\n## Highlights and differences from the Hasura example\n\n- Added email to the JWT (to be used as the user id)\n- added a few requirements to requirements.txt\n- Added a `animal` field to the `user` table\n- Added a new feature to list all the users with their animals\n\n- Added a call to `permit.sync_user()` as part of the sign-up route\n\n  ```python\n  # Let Permit know of the new user\n  # We'll use the email as our unique identifier (in Prod a UUID would be better)\n  user[\"key\"] = user[\"email\"]\n  # Assign a default basic role\n  user[\"roles\"] = [{\"role\":\"admin\", \"tenant\": \"default\"}]\n  userInput = UserInput(**user)\n  # Save to permit\n  permit.write(permit.api.sync_user(userInput))\n  ```\n\n- Added an enforcement point with permit to control who can list animals (fully controlled from Permit's policy-editor in realtime)\n  ```python\n   # enforce app-level access with Permit\n  if permit.check(id, \"list\", \"animals\"):\n      user_response = client.list_animals()\n      return jsonify(user_response[\"data\"][\"user\"])\n  else:\n      return make_response(jsonify({\n          'message': 'Not allowed'\n      } )), 403\n  ```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpermitio%2Fpermit-hasura-python-example","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpermitio%2Fpermit-hasura-python-example","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpermitio%2Fpermit-hasura-python-example/lists"}