API Client Reference¶
Client ¶
An asynchronous client for the Lean Explore backend API.
This client handles making HTTP requests to the API base URL, optionally authenticating with an API key, and parsing responses into Pydantic models.
The client supports three modes of operation: 1. API key only: Uses the default production API base URL with authentication. 2. Base URL only: Uses a custom base URL without authentication (for local servers). 3. Both API key and base URL: Uses a custom base URL with authentication.
Attributes:
| Name | Type | Description |
|---|---|---|
api_key |
Optional[str]
|
The API key used for authenticating requests, if provided. |
timeout |
float
|
The timeout for HTTP requests in seconds. |
base_url |
str
|
The base URL for the API. |
Initializes the API Client.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
api_key
|
Optional[str]
|
Optional API key for authentication. If provided, requests will include an Authorization header. If not provided, requests will be made without authentication. |
None
|
base_url
|
Optional[str]
|
Optional custom base URL for the API. If not provided, defaults to the production API base URL. |
None
|
timeout
|
float
|
Default timeout for HTTP requests in seconds. |
10.0
|
Source code in src/lean_explore/api/client.py
Functions¶
get_by_id
async
¶
Retrieves a specific statement group by its unique ID via the API.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
group_id
|
Union[int, List[int]]
|
The unique identifier of the statement group, or a list of IDs. |
required |
Returns:
| Type | Description |
|---|---|
Union[Optional[APISearchResultItem], List[Optional[APISearchResultItem]]]
|
An APISearchResultItem object if a single ID was found, None if it was |
Union[Optional[APISearchResultItem], List[Optional[APISearchResultItem]]]
|
not found. A list of Optional[APISearchResultItem] if a list of |
Union[Optional[APISearchResultItem], List[Optional[APISearchResultItem]]]
|
IDs was provided. |
Raises:
| Type | Description |
|---|---|
HTTPStatusError
|
If the API returns an HTTP error status other than 404 (e.g., 401, 403, 5xx). |
RequestError
|
For network-related issues or other request errors. |
Source code in src/lean_explore/api/client.py
get_dependencies
async
¶
Retrieves the dependencies (citations) for a specific statement group.
This method fetches the statement groups that the specified 'group_id'(s) depend on (i.e., cite).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
group_id
|
Union[int, List[int]]
|
The unique identifier of the statement group, or a list of IDs. |
required |
Returns:
| Type | Description |
|---|---|
Union[Optional[APICitationsResponse], List[Optional[APICitationsResponse]]]
|
An APICitationsResponse object if a single ID was provided. A list |
Union[Optional[APICitationsResponse], List[Optional[APICitationsResponse]]]
|
of Optional[APICitationsResponse] if a list of IDs was provided. |
Union[Optional[APICitationsResponse], List[Optional[APICitationsResponse]]]
|
None is returned for IDs that are not found. |
Raises:
| Type | Description |
|---|---|
HTTPStatusError
|
If the API returns an HTTP error status other than 404 (e.g., 401, 403, 5xx). |
RequestError
|
For network-related issues or other request errors. |
Source code in src/lean_explore/api/client.py
search
async
¶
Performs a search for statement groups via the API.
This method can handle a single query string or a list of query strings. When a list is provided, requests are sent concurrently.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query
|
Union[str, List[str]]
|
The search query string or a list of query strings. |
required |
package_filters
|
Optional[List[str]]
|
An optional list of package names to filter the search by. This filter is applied to all queries. |
None
|
Returns:
| Type | Description |
|---|---|
Union[APISearchResponse, List[APISearchResponse]]
|
An APISearchResponse object if a single query was provided, or a |
Union[APISearchResponse, List[APISearchResponse]]
|
list of APISearchResponse objects if a list of queries was provided. |
Raises:
| Type | Description |
|---|---|
HTTPStatusError
|
If the API returns an HTTP error status (4xx or 5xx). |
RequestError
|
For network-related issues or other request errors. |