contafi.api_client package
Subpackages
- contafi.api_client.client package
Module contents
ContaFi API client package.
Contains the core client logic and API base classes required to interact with the ContaFi web services.
- class contafi.api_client.ApiBase(api_token=None, api_url=None, api_version=None, api_raise_for_status=True)
Bases:
object
Abstract base class for ContaFi API wrappers.
Used as a foundation for specialized modules that interact with specific API endpoints (e.g., BHE, BTE, invoices, etc.). Provides a preconfigured ApiClient instance to be reused by subclasses.
- Parámetros:
api_token (str) – Authentication token for the ContaFi API.
api_url (str) – Base URL for the ContaFi API.
api_version (str) – API version to use (e.g., «v1»).
api_raise_for_status (bool) – Whether to raise an exception automatically on HTTP error responses. Defaults to True.
- class contafi.api_client.ApiClient(token=None, url=None, version=None, raise_for_status=True)
Bases:
object
Client for interacting with the ContaFi API.
Handles authentication, request headers, URL versioning, and request execution with error handling.
- Parámetros:
token (str) – User authentication token. If not provided, the value will be read from the environment variable CONTAFI_API_TOKEN.
url (str) – Base URL of the API. Defaults to https://contafi.cl or the value of CONTAFI_API_URL.
version (str) – API version. Defaults to “v1”.
raise_for_status (bool) – Whether to raise exceptions on HTTP errors. Defaults to True.
- delete(resource, headers=None)
Send a DELETE request to the specified API resource.
- Parámetros:
resource (str) – API resource path.
headers (dict) – Optional custom headers.
- Devuelve:
HTTP response object.
- Tipo del valor devuelto:
requests.Response
- get(resource, headers=None)
Send a GET request to the specified API resource.
- Parámetros:
resource (str) – API resource path (e.g., «/dte/ventas»).
headers (dict) – Optional custom headers.
- Devuelve:
HTTP response object.
- Tipo del valor devuelto:
requests.Response
- post(resource, data=None, headers=None)
Send a POST request to the specified API resource.
- Parámetros:
resource (str) – API resource path.
data (dict) – Data to send in the request body.
headers (dict) – Optional custom headers.
- Devuelve:
HTTP response object.
- Tipo del valor devuelto:
requests.Response
- put(resource, data=None, headers=None)
Send a PUT request to the specified API resource.
- Parámetros:
resource (str) – API resource path.
data (dict) – Data to send in the request body.
headers (dict) – Optional custom headers.
- Devuelve:
HTTP response object.
- Tipo del valor devuelto:
requests.Response
- exception contafi.api_client.ApiException(message, code=None, params=None)
Bases:
Exception
Custom exception for handling errors in the ContaFi API client.
This exception is raised when an HTTP error, connection failure, timeout, or malformed response occurs. It allows for an optional error code and additional contextual parameters.