/palantir-pack:palantir-sdk-patternsfrom palantir-pack
Provides production-ready Palantir Foundry SDK patterns for Python and TypeScript, including client singletons, typed error handling, pagination helpers, retry logic, and multi-tenant factories.
Ships in palantir-pack. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Production-ready patterns for Foundry Platform SDK and OSDK usage. Covers client singletons, typed error handling, pagination helpers, retry logic, and multi-tenant client factories.
palantir-install-auth setupfoundry-platform-sdk or @osdk/client installed# src/foundry_client.py
import os
import foundry
from functools import lru_cache
@lru_cache(maxsize=1)
def get_client() -> foundry.FoundryClient:
"""Thread-safe singleton — cached after first call."""
auth = foundry.ConfidentialClientAuth(
client_id=os.environ["FOUNDRY_CLIENT_ID"],
client_secret=os.environ["FOUNDRY_CLIENT_SECRET"],
hostname=os.environ["FOUNDRY_HOSTNAME"],
scopes=["api:read-data", "api:write-data"],
)
auth.sign_in_as_service_user()
return foundry.FoundryClient(auth=auth, hostname=os.environ["FOUNDRY_HOSTNAME"])
import foundry
from dataclasses import dataclass
from typing import TypeVar, Generic, Optional
T = TypeVar("T")
@dataclass
class Result(Generic[T]):
data: Optional[T] = None
error: Optional[str] = None
status_code: Optional[int] = None
def safe_call(fn, *args, **kwargs) -> Result:
"""Wrap any Foundry SDK call with structured error handling."""
try:
return Result(data=fn(*args, **kwargs))
except foundry.ApiError as e:
return Result(error=e.message, status_code=e.status_code)
except Exception as e:
return Result(error=str(e))
# Usage
result = safe_call(
get_client().ontologies.OntologyObject.list,
ontology="my-company", object_type="Employee", page_size=10,
)
if result.error:
print(f"Error {result.status_code}: {result.error}")
else:
print(f"Found {len(result.data.data)} objects")
def paginate_objects(client, ontology: str, object_type: str, page_size: int = 100):
"""Iterate through all objects with automatic pagination."""
page_token = None
while True:
result = client.ontologies.OntologyObject.list(
ontology=ontology,
object_type=object_type,
page_size=page_size,
page_token=page_token,
)
yield from result.data
page_token = result.next_page_token
if not page_token:
break
# Usage
for emp in paginate_objects(get_client(), "my-company", "Employee"):
print(emp.properties["fullName"])
import time
import random
def retry_with_backoff(fn, max_retries=3, base_delay=1.0):
"""Retry on 429/5xx with jittered exponential backoff."""
for attempt in range(max_retries + 1):
try:
return fn()
except foundry.ApiError as e:
if attempt == max_retries or e.status_code not in (429, 500, 502, 503):
raise
delay = base_delay * (2 ** attempt) + random.uniform(0, 0.5)
print(f"Retry {attempt + 1}/{max_retries} in {delay:.1f}s (HTTP {e.status_code})")
time.sleep(delay)
import { createClient, type Client } from "@osdk/client";
import { createConfidentialOauthClient } from "@osdk/oauth";
// Singleton with lazy initialization
let _client: Client | null = null;
export function getOsdkClient(): Client {
if (!_client) {
const oauth = createConfidentialOauthClient(
process.env.FOUNDRY_CLIENT_ID!,
process.env.FOUNDRY_CLIENT_SECRET!,
`https://${process.env.FOUNDRY_HOSTNAME}/multipass/api/oauth2/token`,
);
_client = createClient(
`https://${process.env.FOUNDRY_HOSTNAME}`,
process.env.ONTOLOGY_RID!,
oauth,
);
}
return _client;
}
| Pattern | Use Case | Benefit |
|---|---|---|
| Singleton | All API calls | One auth flow, reused connection |
| Result wrapper | Error propagation | No uncaught exceptions |
| Pagination helper | Large datasets | Memory-safe iteration |
| Retry with backoff | Transient failures | Resilient operations |
_clients: dict[str, foundry.FoundryClient] = {}
def get_client_for_tenant(tenant_id: str) -> foundry.FoundryClient:
if tenant_id not in _clients:
hostname = get_tenant_hostname(tenant_id)
token = get_tenant_token(tenant_id)
_clients[tenant_id] = foundry.FoundryClient(
auth=foundry.UserTokenAuth(hostname=hostname, token=token),
hostname=hostname,
)
return _clients[tenant_id]
Apply patterns in palantir-core-workflow-a for real pipeline usage.
What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
24 skills in this plugin
/palantir-ci-integrationConfigure CI/CD pipelines for Palantir Foundry integrations with GitHub Actions.
Use when setting up automated testing, running transforms validation,
or integrating Foundry SDK tests into your build process.
Trigger with phrases like "palantir CI", "foundry GitHub Actions",
"palantir automated tests", "CI foundry".
/palantir-common-errorsDiagnose and fix Palantir Foundry common errors and API exceptions.
Use when encountering Foundry errors, debugging failed API calls,
or troubleshooting transform build failures.
Trigger with phrases like "palantir error", "fix palantir",
"foundry not working", "debug foundry", "palantir 401 403".
/palantir-npx claudepluginhub flight505/skill-forge --plugin palantir-packOther plugins' skills for the same job