If you want to use the Ontology SDK in a compute module you can change the created 3rd Party application for one you have already created with an osdk in your developer console. Here are the in platform docs describing how to do so:
Create the application and generate an OSDK
-
Navigate to Developer Console and create a new application.
-
Choose to also generate an OSDK. Then, add your Ontology objects.
-
Select the Python SDK language option.
-
Select the Backend service application type.
-
Under Data permissions, select Application’s permissions.
Grant access to the application service user
The client ID generated in your Developer Console application must have access to the added Ontology resources to allow the OSDK to access them. To do this, navigate to the OAuth & Scopes tab and select Check access in the Resource access scope section. Here, can view your current access status or navigate to resources to manage access. In the Security tab of the given resource, search for the client ID of your application, then add that user.
Create and add a source to your compute module
By default, egress is disabled for all compute modules. To use the OSDK from a compute module, you must first set up a source for the hostname that you will pass into the OSDK. (Compute modules in platform docs contains how to add a source)
Configure application permissions
After creating a source for the hostname, you can configure permissions for your OSDK application:
-
From the Configure tab of your compute module, scroll to the top of the page and select Application permissions
-
Select Use other app credentials
-
In the dialog that appears, enter the client ID and secret you received in Developer Console. Select Apply, then save your configuration changes.
You can now access the client ID/secret of your application user from within your compute module:
from compute_modules.auth import retrieve_third_party_id_and_creds
client_id, client_secret = retrieve_third_party_id_and_creds()
Build your Docker image
In the Start developing tab of your Developer Console application, you will find a command similar to the one below to install your OSDK library with pip:
pip install pokemon_app_sdk --upgrade \
--extra-index-url "https://user:$FOUNDRY_TOKEN@stack.palantirfoundry.com/artifacts/api/repositories/ri.artifacts.main.repository.8d6eacb5-058c-47c7-a601-cf38cf76de8f/contents/release/pypi/simple" \
--extra-index-url "https://user:$FOUNDRY_TOKEN@stack.palantirfoundry.com/artifacts/api/repositories/ri.foundry-sdk-asset-bundle.main.artifacts.repository/contents/release/pypi/simple"
You can use this same command to build a Docker image with that dependency by adding an ARG
to your Dockerfile.
For example, below is a working requirements.txt
and corresponding Dockerfile
pokemon_app_sdk
foundry-compute-modules>=0.9.0
FROM --platform=linux/amd64 python:3.12
ARG FOUNDRY_TOKEN
COPY requirements.txt .
RUN pip install -r requirements.txt --upgrade \
--extra-index-url "https://user:$FOUNDRY_TOKEN@stack.palantirfoundry.com/artifacts/api/repositories/ri.artifacts.main.repository.8d6eacb5-058c-47c7-a601-cf38cf76de8f/contents/release/pypi/simple" \
--extra-index-url "https://user:$FOUNDRY_TOKEN@stack.palantirfoundry.com/artifacts/api/repositories/ri.foundry-sdk-asset-bundle.main.artifacts.repository/contents/release/pypi/simple"
COPY src .
USER 5000
ENTRYPOINT ["python", "app.py"]
Then, pass your Docker image by passing your FOUNDRY_TOKEN
using --build-arg
:
FOUNDRY_TOKEN=<your-foundry-token>
docker build --build-arg FOUNDRY_TOKEN=$FOUNDRY_TOKEN -t stack-container-registry.palantirfoundry.com/your-compute-module:0.0.1 .