| name | palantir-sdk-patterns |
| description | Apply production-ready Palantir Foundry SDK patterns for Python and TypeScript.
Use when implementing Foundry integrations, refactoring SDK usage,
or establishing team coding standards for Foundry API calls.
Trigger with phrases like "palantir SDK patterns", "foundry best practices",
"palantir code patterns", "idiomatic foundry SDK".
|
| allowed-tools | Read, Write, Edit |
| version | 1.5.0 |
| license | MIT |
| author | Jeremy Longshore <jeremy@intentsolutions.io> |
| tags | ["saas","palantir","foundry","sdk","patterns","typescript"] |
| compatibility | Designed for Claude Code, also compatible with Codex and OpenClaw |
Palantir SDK Patterns
Overview
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.
Prerequisites
- Completed
palantir-install-auth setup
- Familiarity with async/await patterns
foundry-platform-sdk or @osdk/client installed
Instructions
Step 1: Singleton Client (Python)
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"])
Step 2: Typed Error Handling
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[] =
status_code: [] =
() -> Result:
:
Result(data=fn(*args, **kwargs))
foundry.ApiError e:
Result(error=e.message, status_code=e.status_code)
Exception e:
Result(error=(e))
result = safe_call(
get_client().ontologies.OntologyObject.,
ontology=, object_type=, page_size=,
)
result.error:
()
:
()