Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 19 additions & 29 deletions .github/workflows/publish-to-pypi.yml
Original file line number Diff line number Diff line change
@@ -1,31 +1,21 @@
name: Publish Python 🐍 distributions 📦 to PyPI and TestPyPI
on: push
---
name: "Publish to PyPI"
on: "push"
jobs:
build-n-publish:
name: Build and publish Python 🐍 distributions 📦 to PyPI and TestPyPI
runs-on: ubuntu-18.04
publish:
name: "Build & Publish"
runs-on: "ubuntu-latest"
steps:
- uses: actions/checkout@master
- name: Set up Python 3.7
uses: actions/setup-python@v1
with:
python-version: 3.7
- name: Install pypa/build
run: >-
python -m
pip install
build
--user
- name: Build a binary wheel and a source tarball
run: >-
python -m
build
--sdist
--wheel
--outdir dist/
.
- name: Publish distribution 📦 to PyPI
if: startsWith(github.ref, 'refs/tags')
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_API_TOKEN }}
- uses: "actions/checkout@v2"
- uses: "actions/setup-python@v1"
with:
python-version: "3.6"
- name: "Install pypa/build"
run: "python -m pip install build --user"
- name: "Build wheel and source tarball"
run: "python -m build --sdist --wheel --outdir dist/ ."
- name: "Publish"
if: "startsWith(github.ref, 'refs/tags')"
uses: "pypa/gh-action-pypi-publish@release/v1"
with:
password: "${{ secrets.PYPI_API_TOKEN }}"
170 changes: 85 additions & 85 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -1,103 +1,103 @@
name: Test
---
name: "Test"
on:
push:
branches:
- "master"
- "!dependabot/*"
- "*"
pull_request:
branches:
- "*"
- "*"
jobs:
lint:
name: Format & Lint
runs-on: ubuntu-latest
name: "Format & Lint"
runs-on: "ubuntu-latest"
strategy:
fail-fast: false
steps:

- uses: actions/checkout@v2
- name: Set up Python 3.8
uses: actions/setup-python@v1
with:
python-version: 3.8
- name: Setup Python Environment
run: pip install -U pip virtualenv

- name: Install Dependencies
run: |
virtualenv ~/.cache/virtualenv/authzedpy
source ~/.cache/virtualenv/authzedpy/bin/activate
pip install poetry
poetry env info
poetry install
- name: Check for Lint
run: |
source ~/.cache/virtualenv/authzedpy/bin/activate
find . -name "*.py" | grep -v "_pb2" | xargs pyflakes
- name: Check Formatting
run: |
source ~/.cache/virtualenv/authzedpy/bin/activate
black --check --diff .
- name: Checking Imports Ordering
run: |
source ~/.cache/virtualenv/authzedpy/bin/activate
find . -name "*.py" | grep -v "_pb2" | xargs isort --check --diff
- uses: "actions/checkout@v2"
- uses: "bewuethr/yamllint-action@v1.1.1"
with:
config-file: ".yamllint"
- uses: "actions/setup-python@v1"
with:
python-version: "3.8"
- name: "Setup Python Environment"
run: "pip install -U pip virtualenv"
- name: "Install Dependencies"
run: |
virtualenv ~/.cache/virtualenv/authzedpy
source ~/.cache/virtualenv/authzedpy/bin/activate
pip install poetry
poetry env info
poetry install
- name: "Pyflakes"
run: |
source ~/.cache/virtualenv/authzedpy/bin/activate
find . -name "*.py" | grep -v "_pb2" | xargs pyflakes
- name: "Blacken"
run: |
source ~/.cache/virtualenv/authzedpy/bin/activate
black --check --diff .
- name: "Isort"
run: |
source ~/.cache/virtualenv/authzedpy/bin/activate
find . -name "*.py" | grep -v "_pb2" | xargs isort --check --diff

pytest:
name: Unit Tests
runs-on: ubuntu-latest
name: "Unit Tests"
runs-on: "ubuntu-latest"
strategy:
matrix:
python-version: [3.6, 3.7, 3.8, 3.9]
python-version:
- "3.6"
- "3.7"
- "3.8"
- "3.9"
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Setup Python Environment
run: pip install -U pip virtualenv

- name: Install Dependencies
run: |
virtualenv ~/.cache/virtualenv/authzedpy
source ~/.cache/virtualenv/authzedpy/bin/activate
pip install poetry
poetry env info
poetry install
- name: Pytest
run: |
source ~/.cache/virtualenv/authzedpy/bin/activate
pytest -vv .
- uses: "actions/checkout@v2"
- uses: "actions/setup-python@v2"
with:
python-version: "${{ matrix.python-version }}"
- name: "Setup Python Environment"
run: "pip install -U pip virtualenv"
- name: "Install Dependencies"
run: |
virtualenv ~/.cache/virtualenv/authzedpy
source ~/.cache/virtualenv/authzedpy/bin/activate
pip install poetry
poetry env info
poetry install
- name: "Pytest"
run: |
source ~/.cache/virtualenv/authzedpy/bin/activate
pytest -vv .

protobuf:
name: Generate & Diff
runs-on: ubuntu-latest
name: "Generate & Diff"
runs-on: "ubuntu-latest"
steps:
- uses: actions/checkout@v2
- name: Set up Python 3.6
uses: actions/setup-python@v1
with:
python-version: 3.6
- name: Setup Python Environment
run: pip install -U pip virtualenv
- name: Install Homebrew & gRPC
run: |
bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
brew install grpc
- uses: bufbuild/buf-setup-action@v0.1.0
with:
version: '0.43.2'

- name: Install Python Dependencies
run: |
virtualenv ~/.cache/virtualenv/authzedpy
source ~/.cache/virtualenv/authzedpy/bin/activate
pip install poetry
poetry env info
poetry install

- name: Generate & Diff Protos
run: |
source ~/.cache/virtualenv/authzedpy/bin/activate
./buf.gen.yaml
bash -c '[ $(git status --porcelain | tee /dev/fd/2 | wc -c) -eq 0 ]'
- uses: "actions/checkout@v2"
- uses: "actions/setup-python@v1"
with:
python-version: "3.6"
- name: "Setup Python Environment"
run: "pip install -U pip virtualenv"
- name: "Install Homebrew & gRPC"
run: |
bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
brew install grpc
- uses: "bufbuild/buf-setup-action@v0.5.0"
with:
version: "0.56.0"
- name: "Install Python Dependencies"
run: |
virtualenv ~/.cache/virtualenv/authzedpy
source ~/.cache/virtualenv/authzedpy/bin/activate
pip install poetry
poetry env info
poetry install
- name: "Generate & Diff Protos"
run: |
source ~/.cache/virtualenv/authzedpy/bin/activate
./buf.gen.yaml && git diff && bash -c '[ $(git status --porcelain | tee /dev/fd/2 | wc -c) -eq 0 ]'
10 changes: 10 additions & 0 deletions .yamllint
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# vim: ft=yaml
---
yaml-files:
- "*.yaml"
- "*.yml"
- ".yamllint"
extends: "default"
rules:
quoted-strings: "enable"
line-length: "disable"
30 changes: 20 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ This repository houses the Python client library for Authzed.
Developers create a schema that models their permissions requirements and use a client library, such as this one, to apply the schema to the database, insert data into the database, and query the data to efficiently check permissions in their applications.

Supported client API versions:
- [v1](https://docs.authzed.com/reference/api#authzedapiv1)
- [v1alpha1](https://docs.authzed.com/reference/api#authzedapiv1alpha1)
- [v0](https://docs.authzed.com/reference/api#authzedapiv0)
- "arrakisclient" - a deprecated ORM for v0
Expand Down Expand Up @@ -63,9 +64,10 @@ In order to successfully connect, you will have to provide a [Bearer Token] with
[Authzed Dashboard]: https://app.authzed.com

```py
from authzed.api.v0 import Client
from authzed.api.v1 import Client
from grpcutil import bearer_token_credentials


client = Client(
"grpc.authzed.com:443",
bearer_token_credentials("t_your_token_here_1234567deadbeef"),
Expand All @@ -75,17 +77,25 @@ client = Client(
### Performing an API call

```py
from authzed.api.v0 import CheckRequest, ObjectAndRelation, User
from authzed.api.v1 import (
CheckPermissionRequest,
CheckPermissionResponse,
ObjectReference,
SubjectReference,
)


emilia = User("blog/user", "emilia")
read_first_post = ObjectAndRelation(
namespace="blog/post",
object_id="1",
relation="read",
)
post_one = ObjectReference(object_type="blog/post", object_id="1")
emilia = SubjectReference(object=ObjectReference(
object_type="blog/user",
object_id="emilia",
))

# Is Emilia in the set of users that can read post #1?
resp = client.Check(CheckRequest(user=emilia, test_userset=read_first_post))
assert resp.is_member
resp = client.CheckPermission(CheckPermissionRequest(
resource=post_one,
permission="reader",
subject=emilia,
))
assert resp.permissionship == CheckPermissionResponse.PERMISSIONSHIP_HAS_PERMISSION
```
Loading