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.
pip install clio-manage-api-clientimport clio_manage_python_client as Clio
client = Clio.Manage(access_token="your_access_token") # 'store_responses=True' for sqlite response handlerOr
from clio_manage_python_client import Manage as Client
client = Client(access_token="your_access_token")-
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.
- 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
response = client.get.matters() # Default limit is 200
print(json.dumps(response, indent=2))related_contacts = client.get.matters.related_contacts(id=12345, fields="id,name")
print(json.dumps(related_contacts, indent=2))response_all = client.all.matters(fields="id,name")
print(f"Total items retrieved: {len(response_all['data'])}")
print(json.dumps(response_all, indent=2))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))# 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))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")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.
# 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)- 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
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.
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]",
}- The
showendpoint is prioritized ifidis present in thekwargs. - The
indexendpoint is called ifidis not provided.
Handles requests, including:
- Pagination support.
- Query parameter and payload validation.
- Dynamic path formatting with provided arguments.
- 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
This project is licensed under the MIT License.