An unofficial Python client for the Clio Manage API.
Project description
Easy to use python client for the Clio API
This API client is designed to interact with the Clio API, providing robust handling for HTTP request methods, query parameters, payload validation, and dynamic endpoint management.
Installation
pip install clio-manage-api-client
Key Features
-
Dynamic Endpoint Management:
- Dynamically initializes and manages endpoints using metadata from the
models.endpointsmodule. - Supports operations like
index,show,post,patch,deleteas well as sub-methods for relational endpoints (Explained Below) - Endpoints that return content can use the
downloadmethod. Output path can be provided in the call or set within the client
- Dynamically initializes and manages endpoints using metadata from the
-
Integrated Query Parameter and Payload Handling:
- Automatically validates, converts, and processes query parameters and payload data.
- Ensures type safety and required field validation for all inputs.
- Query parameters are processed first and removed from
kwargs. Remainingkwargsare processed for payload data.
-
Pagination Support:
- Handles paginated responses seamlessly when using the
allmethod. - Automatically appends results from all pages.
- Handles paginated responses seamlessly when using the
-
Reserved Keywords and Parameter Mappings:
- Handles reserved keywords and endpoint-specific parameters via a
mappingsdictionary. - Reserved keywords such as
fromandX-API-VERSIONare mapped to their correct representations (e.g.,from_tofrom). - Parameters like
matter_idandidare interchangeable, ensuring ease of use for endpoints that deviate from the general schema.
- Handles reserved keywords and endpoint-specific parameters via a
-
Dynamic Endpoint Resolution:
- Determines whether to call the
indexorshowendpoint based on the presence ofidinkwargs. - For example:
client.get.matters(id=123)calls theshowendpoint.client.get.matters(limit=10)calls theindexendpoint.
- Determines whether to call the
-
Rate Limiting:
- Enforces rate limits using the
RateMonitorclass to ensure compliance with API restrictions.
- Enforces rate limits using the
-
Error Reporting:
- Provides detailed validation error messages when inputs do not meet the expected types or requirements.
Reserved Keywords and Mapping
The client automatically handles reserved keywords and non-standard endpoint parameters through a predefined mappings dictionary. This ensures compatibility and ease of use for all endpoints.
Example Mappings
mappings = {
"X_API_VERSION": "X-API-VERSION",
"from_": "from",
"ids__": "ids",
"jurisdiction__id": "jurisdiction[id]",
"service_type__id": "service_type[id]",
"trigger__id": "trigger[id]",
}
Handling Non-Standard Endpoints
Example Endpoint:
https://app.clio.com/api/v4/matters/{matter_id}/client.jsonhttps://app.clio.com/api/v4/matters/{id}.json
Both matter_id and id can be used interchangeably. The client automatically maps matter_id to id for consistency.
Example Usage
# Calls the 'show' endpoint for a specific matter
response = client.get.matters(id=123)
# Calls the 'client' relation endpoint for a specific matter
response = client.get.matters.client(matter_id=123)
# Calls the 'client' relation endpoint for a specific matter
response = client.get.matters.client(id=123)
Arrays(Needs more testing):
- Can be provided using by including a double underscore
- Any text after the underscores get converted into a query parameter keyword
ids__ = [123,456,789]gets converted toids[]=123&ids[]=456&ids[]=789jurisdiction__id = 123gets converted tojurisdiction[id]=123
Usage
- Models are now generated when the client is first ran directly from the latest API documentation
- The Openapi spec file that is used to generate the dataclasses is now stored in the models/ subdirectory
- Get the latest changes made to the API by using the update.py script. Existing model classes will be backed up
Environment
Using venv
git clone https://github.com/unigrated-solutions/clio-api-python-client.git && cd clio-api-python-client
python -m venv .venv
source .venv/bin/activate
pip install --upgrade pip && pip install -r requirements.txt
Initialization
from client import Client
client = Client(access_token="your_access_token") # 'store_responses=True' for sqlite response handler
Single Request Example
response = client.get.matters() # Default limit is 200
print(json.dumps(response, indent=2))
Relational Endpoint Example
related_contacts = client.get.matters.related_contacts(id=12345, fields="id,name")
print(json.dumps(related_contacts, indent=2))
Fetch All Paginated Results
response_all = client.all.matters(fields="id,name")
print(f"Total items retrieved: {len(response_all['data'])}")
print(json.dumps(response_all, indent=2))
Request With Generated Fields
Using all
# Returns data from all available non nested fields
response = client.get.matters(fields="all", limit=10)
print(json.dumps(response, indent=2))
# With nested fields
response = client.get.matters(fields="all,client{all}", limit=10)
print(json.dumps(response, indent=2))
# Returns the id and etag of every nested resource within the endpoint
response = client.get.matters(fields="all_ids", limit=10)
print(json.dumps(response, indent=2))
Datetime and Timedeltas
# Absolute dates
one_year_ago = date.today() - timedelta(days=365)
response = client.all.matters(limit=200, open_date__= f'>={one_year_ago}', order="open_date(asc)", fields="all,client{name},practice_area{name,category},responsible_attorney{name}")
print(json.dumps(response, indent=2))
# Helper functions: end_of_the_month()
entries = client.all.calendar_entries(fields="start_at,end_at,all_day,location,description,summary,attendees{name}", from_=datetime.now(), to=end_of_the_month())
print(json.dumps(response, indent=2))
Exporting
To Excel Spreadsheet:
Requires pandas < 2.0 and openpyxl
save_to_xlsx(client.all.contacts(fields="all,custom_field_values{field_name,value}"), "contacts.xlsx")
Internal Design
Endpoint Resolution
- The
showendpoint is prioritized ifidis present in thekwargs. - The
indexendpoint is called ifidis not provided.
_request_handler
Handles requests, including:
- Pagination support.
- Query parameter and payload validation.
- Dynamic path formatting with provided arguments.
Known Issues
- On some endpoints, DELETE throws an HTTPEXCEPTION but the command completes successfully in Clio. This can be circumvented by using a try/except block inside the running loop
License
This project is licensed under the MIT License.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file clio_manage_api_client-0.1.0.tar.gz.
File metadata
- Download URL: clio_manage_api_client-0.1.0.tar.gz
- Upload date:
- Size: 29.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e11f55e71900527e94d21404ec0eae8700a4ecdcb61840cb84e42ee54d5b9de1
|
|
| MD5 |
618c41db32fd306445cee302e1d3bf86
|
|
| BLAKE2b-256 |
9c198eb7d7081f20df13f2ffd9fd2860e320431f8a4bcf50c641388bca8a83d4
|
File details
Details for the file clio_manage_api_client-0.1.0-py3-none-any.whl.
File metadata
- Download URL: clio_manage_api_client-0.1.0-py3-none-any.whl
- Upload date:
- Size: 32.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a220ab5238a3e22e7e67f483bcaefcaf9d2299fded5533eaf610810796d2135c
|
|
| MD5 |
0be168bc33089cbb417f25da5cc76690
|
|
| BLAKE2b-256 |
5c37fe72dab6f0a3e652673a73b8fee84008cd3c38cb8b45d45f6ac56f2ba971
|