Skip to main content
Version: 2.0.0

Upload facts via the PDP

To help reduce the data sync latency and wait for data sync before we check permissions on this data. We added a way to send the data updates directly to the PDP, and it will spread it to all the other PDPs (in multi PDP setup)

The way it works is the PDP forwards the facts to the connected OPAL Server and the OPAL Server will then distribute the facts to all the PDPs in the environment. You don't have to worry about the unsupported APIs as the SDK takes care of it for you. This enables you to use the same favorite SDK to interact with the PDP as you previously interacted with Permit Cloud and upload the facts directly to the PDP. It will also ensure all other PDPs running in your environment receive those facts. The way it works is the PDP forwards the facts to the connected OPAL Server and the OPAL Server will then distribute the facts to all the PDPs in the environment.

EAP

Notice that this API is in Early Access Program stage and might be subject to changes.

Min. PDP version required

Notice that this feature is available from PDP version 0.5.1 and above.

How to configure the SDK to upload facts via the PDP

This will allow you to use the same SDK to upload facts via PDP.

from permit import Permit
# This line initializes the SDK and connects your python app
# to the Permit.io PDP container you've set up.
permit = Permit(
# your secret API KEY
token="<your-api-key>",
# In production, you might need to change this URL to fit your deployment
# This is the address where you can find the PDP container.
pdp="http://localhost:7766",
# configure the SDK to upload facts via the PDP
proxy_facts_via_pdp=True,
# Add here any more configurations that you usually use
)

After configuring you can use the normal SDK functions to upload facts and the SDK will take care of the rest.

Wait for the fact to be ready for permission check

Using the following guide you will be able to wait for the PDP to be ready to enforce permission on the newly added facts. Timeout with value 0 will respond immediately without waiting. Timeout with a positive value will wait for the facts to be synced for the specified duration. Timeout with a negative value will wait forever for the facts to be synced.

Important Note

Waiting for the facts to be synced is available only when proxy_facts_via_pdp is enabled

from permit import Permit
# This line initializes the SDK and connects your python app
# to the Permit.io PDP container you've set up.
permit = Permit(
# your secret API KEY
token="<your-api-key>",
# In production, you might need to change this URL to fit your deployment
# This is the address where you can find the PDP container.
pdp="http://localhost:7766",
# configure the SDK to upload facts via the PDP
proxy_facts_via_pdp=True,
# you can set the timeout to wait for the facts to be synced,
# in the initialization of the client - will apply for all the supported SDK calls
# as an argument to the sync_function call - will apply only for the calls inside the context manager
facts_sync_timeout=10,
# Add here any more configurations that you usually use
)

async with permit.wait_for_sync(timeout=15) as p:
user: UserRead = await p.api.users.sync(
{
"key": "auth0|elon",
"email": "elonmusk@tesla.com",
"first_name": "Elon",
"last_name": "Musk",
"attributes": {
"age": 50,
"favorite_color": "red",
},
}
)