### Add and Run Examples Source: https://github.com/papr-ai/papr-pythonsdk/blob/main/CONTRIBUTING.md Demonstrates how to add a new Python example script to the 'examples/' directory and make it executable. The example script is configured to run with Rye. ```Python # add an example to examples/.py #!/usr/bin/env -S rye run python … ``` ```Shell $ chmod +x examples/.py # run the example against your api $ ./examples/.py ``` -------------------------------- ### Build and Install Wheel Source: https://github.com/papr-ai/papr-pythonsdk/blob/main/CONTRIBUTING.md Builds a distributable wheel file for the Papr Python SDK and then installs it using pip. This is an alternative to installing directly from Git. ```Shell $ rye build # or $ python -m build ``` ```Shell $ pip install ./path-to-wheel-file.whl ``` -------------------------------- ### Install from Git Source: https://github.com/papr-ai/papr-pythonsdk/blob/main/CONTRIBUTING.md Installs the Papr Python SDK directly from its Git repository using pip. ```Shell $ pip install git+ssh://git@github.com/Papr-ai/papr-pythonSDK.git ``` -------------------------------- ### Setup Environment with Rye Source: https://github.com/papr-ai/papr-pythonsdk/blob/main/CONTRIBUTING.md Installs dependencies using Rye, a Python dependency manager. It first runs a bootstrap script and then synchronizes all features. Alternatively, it shows how to activate the virtual environment manually. ```Shell $ ./scripts/bootstrap ``` ```Shell $ rye sync --all-features ``` ```Shell # Activate the virtual environment - https://docs.python.org/3/library/venv.html#how-venvs-work $ source .venv/bin/activate # now you can omit the `rye run` prefix $ python script.py ``` -------------------------------- ### Install Papr Python SDK Source: https://github.com/papr-ai/papr-pythonsdk/blob/main/README.md Installs the Papr Python SDK from PyPI using pip. This is the standard way to get the library into your Python environment. ```sh pip install papr_memory ``` -------------------------------- ### Setup Environment without Rye Source: https://github.com/papr-ai/papr-pythonsdk/blob/main/CONTRIBUTING.md Installs dependencies using pip for users who do not wish to install Rye. It requires ensuring the correct Python version is specified and then installing from a requirements lock file. ```Shell $ pip install -r requirements-dev.lock ``` -------------------------------- ### Install Papr Python SDK with aiohttp support Source: https://github.com/papr-ai/papr-pythonsdk/blob/main/README.md Installs the Papr Python SDK with optional aiohttp support for improved asynchronous performance. This is done by specifying the `aiohttp` extra during installation. ```sh pip install papr_memory[aiohttp] ``` -------------------------------- ### Run Tests Source: https://github.com/papr-ai/papr-pythonsdk/blob/main/CONTRIBUTING.md Executes the test suite for the Papr Python SDK. ```Shell $ ./scripts/test ``` -------------------------------- ### Run Mock Server for Tests Source: https://github.com/papr-ai/papr-pythonsdk/blob/main/CONTRIBUTING.md Sets up a mock server using Prism, a tool that mocks API behavior based on an OpenAPI specification. This is a prerequisite for running most tests. ```Shell # you will need npm installed $ npx prism mock path/to/your/openapi.yml ``` -------------------------------- ### Publish to PyPI Manually Source: https://github.com/papr-ai/papr-pythonsdk/blob/main/CONTRIBUTING.md Provides instructions for manually releasing a package to PyPI. This involves setting a PYPI_TOKEN environment variable and running a specific script. ```Shell If you need to manually release a package, you can run the `bin/publish-pypi` script with a `PYPI_TOKEN` set on the environment. ``` -------------------------------- ### Publish to PyPI with GitHub Workflow Source: https://github.com/papr-ai/papr-pythonsdk/blob/main/CONTRIBUTING.md Details how to publish new releases to PyPI using a GitHub Actions workflow. This requires specific organization or repository secrets to be configured. ```Shell You can release to package managers by using [the `Publish PyPI` GitHub action](https://www.github.com/Papr-ai/papr-pythonSDK/actions/workflows/publish-pypi.yml). This requires a setup organization or repository secret to be set up. ``` -------------------------------- ### Lint and Format Code Source: https://github.com/papr-ai/papr-pythonsdk/blob/main/CONTRIBUTING.md Applies linting and formatting to the codebase using Ruff and Black. The scripts automatically fix issues. ```Shell $ ./scripts/lint ``` ```Shell $ ./scripts/format ``` -------------------------------- ### Get Papr Python SDK Version Source: https://github.com/papr-ai/papr-pythonsdk/blob/main/README.md Shows how to retrieve the currently installed version of the Papr Python SDK at runtime. This is useful for debugging or ensuring compatibility with specific features. ```Python import papr_memory print(papr_memory.__version__) ``` -------------------------------- ### Get Feedback by ID with Papr Python SDK Source: https://github.com/papr-ai/papr-pythonsdk/blob/main/api.md Retrieves a specific feedback entry by its feedback_id using the Papr Python SDK. This method returns a FeedbackResponse object. ```Python from papr_memory.types import FeedbackResponse # Assuming 'client' is an initialized Papr client instance # feedback_id is the ID of the feedback to retrieve feedback_response = client.feedback.get_by_id(feedback_id) print(feedback_response) ``` -------------------------------- ### Get User by ID with Papr Python SDK Source: https://github.com/papr-ai/papr-pythonsdk/blob/main/api.md Retrieves a specific user by their user_id using the Papr Python SDK. This method returns a UserResponse object containing the user's details. ```Python from papr_memory.types import UserResponse # Assuming 'client' is an initialized Papr client instance # user_id is the ID of the user to retrieve user_response = client.user.get(user_id) print(user_response) ``` -------------------------------- ### Get Memory by ID with Papr Python SDK Source: https://github.com/papr-ai/papr-pythonsdk/blob/main/api.md Retrieves a specific memory by its memory_id using the Papr Python SDK. This method returns a SearchResponse object containing the memory details. ```Python from papr_memory.types import SearchResponse # Assuming 'client' is an initialized Papr client instance # memory_id is the ID of the memory to retrieve search_response = client.memory.get(memory_id) print(search_response) ``` -------------------------------- ### Create User with Papr Python SDK (Synchronous) Source: https://github.com/papr-ai/papr-pythonsdk/blob/main/README.md Demonstrates how to create a user using the synchronous Papr Python client. It shows how to initialize the client with an API key and make a user creation request. ```python import os from papr_memory import Papr client = Papr( x_api_key=os.environ.get("PAPR_MEMORY_API_KEY"), # This is the default and can be omitted ) user_response = client.user.create( external_id="demo_user_123", email="user@example.com", ) print(user_response.external_id) ``` -------------------------------- ### Create User with Papr Python SDK (Async with aiohttp) Source: https://github.com/papr-ai/papr-pythonsdk/blob/main/README.md Demonstrates creating a user using the asynchronous Papr Python client with `aiohttp` as the HTTP backend. This requires instantiating the client with `http_client=DefaultAioHttpClient()`. ```python import asyncio from papr_memory import DefaultAioHttpClient from papr_memory import AsyncPapr async def main() -> None: async with AsyncPapr( x_api_key="My X API Key", http_client=DefaultAioHttpClient(), ) as client: user_response = await client.user.create( external_id="demo_user_123", email="user@example.com", ) print(user_response.external_id) asyncio.run(main()) ``` -------------------------------- ### Create User with Papr Python SDK (Asynchronous) Source: https://github.com/papr-ai/papr-pythonsdk/blob/main/README.md Shows how to create a user using the asynchronous Papr Python client. This involves using `AsyncPapr` and `await` for API calls within an async function. ```python import os import asyncio from papr_memory import AsyncPapr client = AsyncPapr( x_api_key=os.environ.get("PAPR_MEMORY_API_KEY"), # This is the default and can be omitted ) async def main() -> None: user_response = await client.user.create( external_id="demo_user_123", email="user@example.com", ) print(user_response.external_id) asyncio.run(main()) ``` -------------------------------- ### Manage Papr Client Lifecycle with Context Manager Source: https://github.com/papr-ai/papr-pythonsdk/blob/main/README.md Demonstrates the recommended way to manage the Papr client's HTTP resources using a context manager. This ensures that the client and its underlying connections are properly closed when exiting the `with` block. ```Python from papr_memory import Papr with Papr() as client: # make requests here ... ``` -------------------------------- ### Create User with Papr Python SDK Source: https://github.com/papr-ai/papr-pythonsdk/blob/main/api.md Creates a new user using the Papr Python SDK. This method takes user creation parameters and returns a UserResponse object. It depends on the UserCreateParams type for input. ```Python from papr_memory.types import UserResponse # Assuming 'client' is an initialized Papr client instance # params would be a dictionary containing user creation details user_response = client.user.create(**params) print(user_response) ``` -------------------------------- ### Enable Papr Logging Source: https://github.com/papr-ai/papr-pythonsdk/blob/main/README.md Explains how to enable logging for the Papr SDK using the standard Python `logging` module. Logging levels can be set via the `PAPR_LOG` environment variable. ```shell $ export PAPR_LOG=info ``` -------------------------------- ### Configure Papr Client with Custom HTTP Client Source: https://github.com/papr-ai/papr-pythonsdk/blob/main/README.md Illustrates how to configure the Papr client with a custom `httpx.Client` instance. This allows for advanced configurations such as setting proxies, custom transports, and other advanced HTTP client functionalities. ```Python import httpx from papr_memory import Papr, DefaultHttpxClient client = Papr( # Or use the `PAPR_BASE_URL` env var base_url="http://my.test.server.example.com:8083", http_client=DefaultHttpxClient( proxy="http://my.test.proxy.example.com", transport=httpx.HTTPTransport(local_address="0.0.0.0"), ), ) ``` -------------------------------- ### Create Batch Users with Papr Python SDK Source: https://github.com/papr-ai/papr-pythonsdk/blob/main/api.md Creates multiple users in a batch using the Papr Python SDK. This method takes batch creation parameters and returns a UserCreateBatchResponse object. It depends on the UserCreateBatchParams type for input. ```Python from papr_memory.types import UserCreateBatchResponse # Assuming 'client' is an initialized Papr client instance # params would be a dictionary containing batch user creation details user_create_batch_response = client.user.create_batch(**params) print(user_create_batch_response) ``` -------------------------------- ### Configure Papr Timeouts Source: https://github.com/papr-ai/papr-pythonsdk/blob/main/README.md Illustrates how to set request timeouts for the Papr client. Timeouts can be configured globally or on a per-request basis, accepting float values or `httpx.Timeout` objects for granular control. ```python from papr_memory import Papr import httpx # Configure the default for all requests: client = Papr( # 20 seconds (default is 1 minute) timeout=20.0, ) # More granular control: client = Papr( timeout=httpx.Timeout(60.0, read=5.0, write=10.0, connect=2.0), ) # Override per-request: client.with_options(timeout=5.0).user.create( external_id="demo_user_123", email="user@example.com", ) ``` -------------------------------- ### Handle Papr API Errors Source: https://github.com/papr-ai/papr-pythonsdk/blob/main/README.md Demonstrates how to catch specific Papr API errors like APIConnectionError, RateLimitError, and APIStatusError. It shows how to access error details such as status codes and underlying causes. ```python import papr_memory from papr_memory import Papr client = Papr() try: client.user.create( external_id="demo_user_123", email="user@example.com", ) except papr_memory.APIConnectionError as e: print("The server could not be reached") print(e.__cause__) # an underlying Exception, likely raised within httpx. except papr_memory.RateLimitError as e: print("A 429 status code was received; we should back off a bit.") except papr_memory.APIStatusError as e: print("Another non-200-range status code was received") print(e.status_code) print(e.response) ``` -------------------------------- ### Submit Feedback with Papr Python SDK Source: https://github.com/papr-ai/papr-pythonsdk/blob/main/api.md Submits feedback using the Papr Python SDK. This method takes feedback submission parameters and returns a FeedbackResponse object. It depends on the FeedbackRequest type for input. ```Python from papr_memory.types import FeedbackResponse # Assuming 'client' is an initialized Papr client instance # params would be a dictionary containing feedback details feedback_response = client.feedback.submit(**params) print(feedback_response) ``` -------------------------------- ### List Users with Papr Python SDK Source: https://github.com/papr-ai/papr-pythonsdk/blob/main/api.md Retrieves a list of users using the Papr Python SDK. This method accepts optional parameters for filtering and pagination, returning a UserListResponse object. It depends on the UserListParams type for input. ```Python from papr_memory.types import UserListResponse # Assuming 'client' is an initialized Papr client instance # params can include filters or pagination details user_list_response = client.user.list(**params) print(user_list_response) ``` -------------------------------- ### Submit Batch Feedback with Papr Python SDK Source: https://github.com/papr-ai/papr-pythonsdk/blob/main/api.md Submits multiple feedback entries in a batch using the Papr Python SDK. This method takes batch feedback submission parameters and returns a BatchResponse object. It depends on the BatchRequest type for input. ```Python from papr_memory.types import BatchResponse # Assuming 'client' is an initialized Papr client instance # params would be a dictionary containing batch feedback details batch_response = client.feedback.submit_batch(**params) print(batch_response) ``` -------------------------------- ### Access Raw Response Data Source: https://github.com/papr-ai/papr-pythonsdk/blob/main/README.md Demonstrates how to access the raw HTTP response, including headers, by prefixing method calls with `.with_raw_response.`. The parsed response object can then be obtained using `.parse()`. ```python from papr_memory import Papr client = Papr() response = client.user.with_raw_response.create( external_id="demo_user_123", email="user@example.com", ) print(response.headers.get('X-My-Header')) user = response.parse() # get the object that `user.create()` would have returned print(user.external_id) ``` -------------------------------- ### Stream Response Body with Context Manager Source: https://github.com/papr-ai/papr-pythonsdk/blob/main/README.md Demonstrates how to use `.with_streaming_response` to stream the response body using a context manager. This approach defers reading the response body until methods like `.read()`, `.text()`, or `.iter_lines()` are called, and ensures the response is properly closed. ```Python with client.user.with_streaming_response.create( external_id="demo_user_123", email="user@example.com", ) as response: print(response.headers.get("X-My-Header")) for line in response.iter_lines(): print(line) ``` -------------------------------- ### Make Undocumented POST Request Source: https://github.com/papr-ai/papr-pythonsdk/blob/main/README.md Shows how to make requests to undocumented endpoints using `client.post`. It specifies the endpoint, provides a request body, and casts the response to an `httpx.Response` object for direct access to headers and other properties. ```Python import httpx response = client.post( "/foo", cast_to=httpx.Response, body={"my_param": True}, ) print(response.headers.get("x-foo")) ``` -------------------------------- ### Update Memory with Nested Metadata using Papr Python SDK Source: https://github.com/papr-ai/papr-pythonsdk/blob/main/README.md Illustrates updating memory with nested metadata using the Papr Python SDK. The `metadata` parameter is a dictionary typed using `TypedDict`, showcasing how to pass structured data. ```python from papr_memory import Papr client = Papr() memory = client.memory.update( memory_id="memory_id", metadata={ "emoji_tags": ["string"], "emotion_tags": ["string"], "topics": ["string"], }, ) print(memory.metadata) ``` -------------------------------- ### Add Batch Memories with Papr Python SDK Source: https://github.com/papr-ai/papr-pythonsdk/blob/main/api.md Adds multiple memories in a batch using the Papr Python SDK. This method takes batch memory addition parameters and returns a MemoryAddBatchResponse object. It depends on the MemoryAddBatchParams type for input. ```Python from papr_memory.types import MemoryAddBatchResponse # Assuming 'client' is an initialized Papr client instance # params would be a dictionary containing batch memory addition details memory_add_batch_response = client.memory.add_batch(**params) print(memory_add_batch_response) ``` -------------------------------- ### Search Memories with Papr Python SDK Source: https://github.com/papr-ai/papr-pythonsdk/blob/main/api.md Searches for memories using the Papr Python SDK. This method accepts search parameters and returns a SearchResponse object. It depends on the MemorySearchParams type for input. ```Python from papr_memory.types import SearchResponse # Assuming 'client' is an initialized Papr client instance # params would be a dictionary containing search criteria search_response = client.memory.search(**params) print(search_response) ``` -------------------------------- ### Add Memory with Papr Python SDK Source: https://github.com/papr-ai/papr-pythonsdk/blob/main/api.md Adds a new memory using the Papr Python SDK. This method takes memory addition parameters and returns an AddMemoryResponse object. It depends on the AddMemoryParams type for input. ```Python from papr_memory.types import AddMemoryResponse # Assuming 'client' is an initialized Papr client instance # params would be a dictionary containing memory details add_memory_response = client.memory.add(**params) print(add_memory_response) ``` -------------------------------- ### Update User with Papr Python SDK Source: https://github.com/papr-ai/papr-pythonsdk/blob/main/api.md Updates an existing user identified by user_id using the Papr Python SDK. This method accepts user update parameters and returns a UserResponse object. It depends on the UserUpdateParams type for input. ```Python from papr_memory.types import UserResponse # Assuming 'client' is an initialized Papr client instance # user_id is the ID of the user to update # params would be a dictionary containing user update details user_response = client.user.update(user_id, **params) print(user_response) ``` -------------------------------- ### Configure Papr Retries Source: https://github.com/papr-ai/papr-pythonsdk/blob/main/README.md Shows how to configure the number of automatic retries for API requests. Retries can be disabled by setting `max_retries` to 0 or configured per-request using `with_options`. ```python from papr_memory import Papr # Configure the default for all requests: client = Papr( # default is 2 max_retries=0, ) # Or, configure per-request: client.with_options(max_retries=5).user.create( external_id="demo_user_123", email="user@example.com", ) ``` -------------------------------- ### Differentiate Null vs. Missing Fields Source: https://github.com/papr-ai/papr-pythonsdk/blob/main/README.md Provides a method to distinguish between a field explicitly set to `null` and a field that is missing entirely in an API response. This is achieved by checking the `model_fields_set` attribute. ```python if response.my_field is None: if 'my_field' not in response.model_fields_set: print('Got json like {}, without a "my_field" key present at all.') else: print('Got json like {"my_field": null}.') ``` -------------------------------- ### Update Memory with Papr Python SDK Source: https://github.com/papr-ai/papr-pythonsdk/blob/main/api.md Updates an existing memory identified by memory_id using the Papr Python SDK. This method accepts memory update parameters and returns a MemoryUpdateResponse object. It depends on the MemoryUpdateParams type for input. ```Python from papr_memory.types import MemoryUpdateResponse # Assuming 'client' is an initialized Papr client instance # memory_id is the ID of the memory to update # params would be a dictionary containing memory update details memory_update_response = client.memory.update(memory_id, **params) print(memory_update_response) ``` -------------------------------- ### Delete User with Papr Python SDK Source: https://github.com/papr-ai/papr-pythonsdk/blob/main/api.md Deletes a user identified by user_id using the Papr Python SDK. This method accepts optional parameters and returns a UserDeleteResponse object. It depends on the UserDeleteParams type for input. ```Python from papr_memory.types import UserDeleteResponse # Assuming 'client' is an initialized Papr client instance # user_id is the ID of the user to delete # params can include additional deletion options user_delete_response = client.user.delete(user_id, **params) print(user_delete_response) ``` -------------------------------- ### Delete Memory with Papr Python SDK Source: https://github.com/papr-ai/papr-pythonsdk/blob/main/api.md Deletes a memory identified by memory_id using the Papr Python SDK. This method accepts optional parameters and returns a MemoryDeleteResponse object. It depends on the MemoryDeleteParams type for input. ```Python from papr_memory.types import MemoryDeleteResponse # Assuming 'client' is an initialized Papr client instance # memory_id is the ID of the memory to delete # params can include additional deletion options memory_delete_response = client.memory.delete(memory_id, **params) print(memory_delete_response) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.