Skip to main content


In this document you can find code examples for the Ory Python SDK.


Missing an example? Please create a feature request and it will be added here.

You can find more examples of SDK usage in the auto-generated documentation for [ory-client] (


If you are starting from scratch, first set up a new Python project

mkdir myproject
cd myproject

Install the Ory Python SDK

pip install

If the python package is hosted on a repository, you can install directly using:

pip install git+

You may need to run pip with root permission: sudo pip install git+

Then import the package:

import ory_client


Install via Setuptools.

python install --user

Or use sudo python install to install the package for all users.

Then import the package:

import ory_client


As an example, let's check for whether a given subject has the necessary permissions.


Bearer Authentication (oryAccessToken):

import time
import ory_client
from ory_client.api import permission_api
from ory_client.model.check_permission_result import CheckPermissionResult
from ory_client.model.error_generic import ErrorGeneric
from pprint import pprint
# Defining the host is optional and defaults to
# See for a list of all supported configuration parameters.
# The client must configure the authentication and authorization parameters
# in accordance with the API server security policy.
# Examples for each auth method are provided below, use the example that
# satisfies your auth use case.
# Configure Bearer authorization: oryAccessToken
configuration = ory_client.Configuration(
host = ""
access_token = 'YOUR_BEARER_TOKEN'

# Enter a context with an instance of the API client
with ory_client.ApiClient(configuration) as api_client:
# Create an instance of the API class
api_instance = permission_api.PermissionApi(api_client)
namespace = "namespace_example" # str | Namespace of the Relationship (optional)
object = "object_example" # str | Object of the Relationship (optional)
relation = "relation_example" # str | Relation of the Relationship (optional)
subject_id = "subject_id_example" # str | SubjectID of the Relationship (optional)
subject_set_namespace = "subject_set.namespace_example" # str | Namespace of the Subject Set (optional)
subject_set_object = "subject_set.object_example" # str | Object of the Subject Set (optional)
subject_set_relation = "subject_set.relation_example" # str | Relation of the Subject Set (optional)
max_depth = 1 # int | (optional)

# example passing only required values which don't have defaults set
# and optional values
# Check a permission
api_response = api_instance.check_permission(namespace=namespace, object=object, relation=relation, subject_id=subject_id, subject_set_namespace=subject_set_namespace, subject_set_object=subject_set_object, subject_set_relation=subject_set_relation, max_depth=max_depth)
except ory_client.ApiException as e:
print("Exception when calling PermissionApi->check_permission: %s\n" % e)