APIMatic Core Library for Python

0.2.24 · active · verified Thu Apr 16

APIMatic Core is a foundational Python library (v0.2.24) that provides the essential logic and utilities for consuming REST APIs. It's primarily used as a dependency for Python SDKs generated by APIMatic, aiming to offer a consistent and robust developer experience. The library receives frequent minor updates, focusing on new features, bug fixes, and dependency bumps.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to configure global settings that would be utilized by an APIMatic-generated SDK. It also shows how to catch a generic `ApiException`, a common pattern when working with generated clients.

import os
from apimatic_core.configurations.global_configuration import GlobalConfiguration
from apimatic_core.http.requests_client.requests_client import RequestsClient

# This library is primarily used by generated SDKs. 
# Direct usage often involves configuring global settings 
# or handling generic exceptions.

# Example: Configure global HTTP client settings
GlobalConfiguration.set_timeout(30) # seconds
GlobalConfiguration.set_user_agent("MyCustomApp/1.0")
GlobalConfiguration.set_verify_ssl(True)

# Optionally provide a custom HTTP client instance
# GlobalConfiguration.set_http_client(RequestsClient())

print(f"Global API Timeout: {GlobalConfiguration.get_timeout()} seconds")
print(f"Global User-Agent: {GlobalConfiguration.get_user_agent()}")
print(f"Global SSL Verification: {GlobalConfiguration.get_verify_ssl()}")

# In a generated SDK, these settings would now apply.
# For example, if you had an SDK generated by APIMatic:
# from my_generated_sdk.client import MyClient
# client = MyClient()
# ... the client would use the configured settings

# Example for handling a generic API exception (would typically come from a generated SDK call)
try:
    # Simulate an operation that might raise an ApiException
    raise ApiException("Resource not found", 404, {'X-Request-ID': 'abc'})
except ApiException as e:
    print(f"Caught API Exception: {e.message} (Status: {e.response_code})")
    print(f"Headers: {e.response_headers}")

view raw JSON →