The official Python SDK for the G-PORTAL gpcore API.
This is the Python counterpart to gpcore-go. It provides a pre-configured OIDC client and auto-generated protobuf/gRPC bindings for interacting with the gpcore API.
pip install gpcore-sdkThe following example authenticates using the client credentials flow and fetches the current user:
import grpc
from gpcore_sdk.client import APIClient
from gpcore_sdk.auth_strategies import (
ClientCredentialsStrategy,
CachedAuthStrategy,
)
from gpcore_sdk.protos.gpcore.api.auth.v1.rpc_pb2_grpc import AuthServiceStub
from gpcore_sdk.protos.gpcore.api.admin.v1.requests_pb2 import GetUserRequest
def main():
auth = ClientCredentialsStrategy(
client_id="YOUR_CLIENT_ID",
client_secret="YOUR_CLIENT_SECRET",
)
client = APIClient(strategy=CachedAuthStrategy(auth, 30))
stub = AuthServiceStub(client.channel)
try:
response = stub.GetUser(GetUserRequest())
print(f"User: {response}")
except grpc.RpcError as e:
print(f"gRPC error: {e.code()} - {e.details()}")
if __name__ == "__main__":
main()| Strategy | Description |
|---|---|
ClientCredentialsStrategy |
OAuth2 client credentials flow. Recommended for service-to-service authentication. |
UserPasswordStrategy |
Resource owner password flow. Requires a dedicated Keycloak OIDC client. |
CachedAuthStrategy |
Wrapper that caches and auto-refreshes tokens from any underlying strategy. |
If the API definitions have changed, regenerate the Python protobuf/gRPC code:
scripts/update_proto.shpip install -e .- Update the version in
pyproject.toml. - Commit, tag with the version number, and push the tag.
- The GitHub Actions workflow will build and publish to PyPI automatically.
This project is licensed under the Apache License 2.0.