Skip to content

G-PORTAL/gpcore-py

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

gpcore-py

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.

Installation

pip install gpcore-sdk

Usage

The 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()

Authentication Strategies

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.

Development

Regenerating protobuf bindings

If the API definitions have changed, regenerate the Python protobuf/gRPC code:

scripts/update_proto.sh

Local install

pip install -e .

Releasing

  1. Update the version in pyproject.toml.
  2. Commit, tag with the version number, and push the tag.
  3. The GitHub Actions workflow will build and publish to PyPI automatically.

License

This project is licensed under the Apache License 2.0.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors