$ show Parcle-AI/parcle-memory
The Parcle Python client is a library for interacting with the Parcle Memory API, which provides long-term memory for AI agents. It enables developers to store conversational data and files per user, and then retrieve relevant information through natural language queries that return synthesized answers with citations. The client handles all aspects of communication with the API, including authentication, request retries, file uploads, and processing of Server-Sent Events for search operations. The architecture is straightforward: a synchronous HTTP client built on top of `httpx`, with methods corresponding to each API endpoint. Key features include robust error handling via a well-defined exception hierarchy, automatic retry logic for transient failures, and flexible file upload support that accepts various input types while enforcing size limits. The search method uniquely handles SSE streams to deliver incremental responses, ensuring compatibility with the API's streaming behavior. While the library is purpose-built for the Parcle API, it exhibits several reusable patterns. The exception mapping system in `exceptions.py` can be adapted for any HTTP API, and the file upload handling functions in `client.py` demonstrate a robust approach to processing diverse file inputs. The codebase is actively maintained, has low technical debt, and includes comprehensive tests that mock HTTP interactions to ensure reliability.
The LLM identified 2 files worth highlighting for reuse:
Defines a hierarchy of exceptions that map HTTP status codes to specific exception types, preserving error details from the API. The error_from_response function converts HTTP responses into appropriate exceptions. This pattern is reusable in any HTTP client to provide clear, typed error handling with minimal external dependencies.
Includes helper functions (_prepare_file, _guess_content_type, _content_size, _drop_none) that robustly handle file uploads from various input types (paths, bytes, streams, tuples). They perform size checking, content type inference, and handle edge cases like seeking in streams. This pattern is reusable in any file upload scenario to ensure robust and user-friendly file handling with minimal dependencies.