Conjure Python Client

3.3.0 · active · verified Thu Apr 16

The Conjure Python Client (conjure-python-client) is a Python library that provides a simple interface for executing statically typed remote procedure calls (RPC) from Python. It acts as the RPC layer for clients generated by the `conjure-python` toolchain, leveraging the `requests` library for HTTP communication. Currently at version 3.3.0, the library is actively maintained with regular releases.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize a Conjure client for a generated service. It configures the `RequestsClient` with service URIs and a user agent, then shows how to call a method on a hypothetical generated service interface, including passing an authentication header. The `MyGeneratedService` placeholder should be replaced with an actual service client class generated by the `conjure-python` toolchain for your specific API definition.

import os
from conjure_python_client import RequestsClient, ServiceConfiguration

# Assume 'MyGeneratedService' is a service interface generated by conjure-python
# and imported from your project or another package.
# Example: from my_api_client import MyGeneratedService

# Define a dummy service for demonstration if MyGeneratedService isn't available
class MyGeneratedService:
    def __init__(self, client):
        self._client = client
    
    def get_data(self, auth_header, query_param):
        print(f"Making GET request for data with param: {query_param}")
        # In a real scenario, this would call self._client._request(...)
        if auth_header == 'Bearer valid-token':
            return f"Successfully retrieved data for '{query_param}'"
        else:
            raise ValueError("Invalid authentication")


# Configure the service client
config = ServiceConfiguration()
config.uris = [os.environ.get('CONJURE_API_URI', 'http://localhost:8080/api')]

# Replace 'MyGeneratedService' with your actual generated service class
try:
    service = RequestsClient.create(
        MyGeneratedService,
        user_agent="my-application/1.0.0",
        service_config=config
    )

    # Example usage: making an authenticated call
    auth_token = os.environ.get('CONJURE_AUTH_TOKEN', 'valid-token')
    auth_header = f"Bearer {auth_token}"
    result = service.get_data(auth_header, query_param="example_id")
    print(result)

except Exception as e:
    print(f"An error occurred: {e}")

view raw JSON →