Developer-friendly & type-safe Python SDK specifically catered to leverage apideck-unify API.
Apideck: The Apideck OpenAPI Spec: SDK Optimized
For more information about the API: Apideck Developer Docs
The SDK can be installed with either pip or poetry package managers.
PIP is the default package installer for Python, enabling easy installation and management of packages from PyPI via the command line.
pip install apideck-unify
Poetry is a modern tool that simplifies dependency management and package publishing by using a single pyproject.toml
file to handle project metadata and dependencies.
poetry add apideck-unify
Generally, the SDK will work well with most IDEs out of the box. However, when using PyCharm, you can enjoy much better integration with Pydantic by installing an additional plugin.
# Synchronous Example
from apideck_unify import Apideck
import os
with Apideck(
api_key=os.getenv("APIDECK_API_KEY", ""),
consumer_id="test-consumer",
app_id="dSBdXd2H6Mqwfg0atXHXYcysLJE9qyn1VwBtXHX",
) as apideck:
res = apideck.accounting.tax_rates.list(service_id="salesforce", filter_={
"assets": True,
"equity": True,
"expenses": True,
"liabilities": True,
"revenue": True,
}, pass_through={
"search": "San Francisco",
}, fields="id,updated_at")
while res is not None:
# Handle items
res = res.next()
The same SDK client can also be used to make asychronous requests by importing asyncio.
# Asynchronous Example
from apideck_unify import Apideck
import asyncio
import os
async def main():
async with Apideck(
api_key=os.getenv("APIDECK_API_KEY", ""),
consumer_id="test-consumer",
app_id="dSBdXd2H6Mqwfg0atXHXYcysLJE9qyn1VwBtXHX",
) as apideck:
res = await apideck.accounting.tax_rates.list_async(service_id="salesforce", filter_={
"assets": True,
"equity": True,
"expenses": True,
"liabilities": True,
"revenue": True,
}, pass_through={
"search": "San Francisco",
}, fields="id,updated_at")
while res is not None:
# Handle items
res = res.next()
asyncio.run(main())
This SDK supports the following security scheme globally:
Name | Type | Scheme | Environment Variable |
---|---|---|---|
api_key |
http | HTTP Bearer | APIDECK_API_KEY |
To authenticate with the API the api_key
parameter must be set when initializing the SDK client instance. For example:
from apideck_unify import Apideck
import os
with Apideck(
api_key=os.getenv("APIDECK_API_KEY", ""),
consumer_id="test-consumer",
app_id="dSBdXd2H6Mqwfg0atXHXYcysLJE9qyn1VwBtXHX",
) as apideck:
res = apideck.accounting.tax_rates.list(service_id="salesforce", filter_={
"assets": True,
"equity": True,
"expenses": True,
"liabilities": True,
"revenue": True,
}, pass_through={
"search": "San Francisco",
}, fields="id,updated_at")
while res is not None:
# Handle items
res = res.next()
Available methods
- get - Get Aged Debtors
- list - List Attachments
- get - Get Attachment
- delete - Delete Attachment
- download - Download Attachment
- get - Get BalanceSheet
- list - List Bill Payments
- create - Create Bill Payment
- get - Get Bill Payment
- update - Update Bill Payment
- delete - Delete Bill Payment
- get - Get company info
- list - List Credit Notes
- create - Create Credit Note
- get - Get Credit Note
- update - Update Credit Note
- delete - Delete Credit Note
- list - List Customers
- create - Create Customer
- get - Get Customer
- update - Update Customer
- delete - Delete Customer
- list - List Departments
- create - Create Department
- get - Get Department
- update - Update Department
- delete - Delete Department
- list - List Expenses
- create - Create Expense
- get - Get Expense
- update - Update Expense
- delete - Delete Expense
- list - List Invoice Items
- create - Create Invoice Item
- get - Get Invoice Item
- update - Update Invoice Item
- delete - Delete Invoice Item
- list - List Invoices
- create - Create Invoice
- get - Get Invoice
- update - Update Invoice
- delete - Delete Invoice
- list - List Journal Entries
- create - Create Journal Entry
- get - Get Journal Entry
- update - Update Journal Entry
- delete - Delete Journal Entry
- list - List Ledger Accounts
- create - Create Ledger Account
- get - Get Ledger Account
- update - Update Ledger Account
- delete - Delete Ledger Account
- list - List Locations
- create - Create Location
- get - Get Location
- update - Update Location
- delete - Delete Location
- list - List Payments
- create - Create Payment
- get - Get Payment
- update - Update Payment
- delete - Delete Payment
- get - Get Profit and Loss
- list - List Purchase Orders
- create - Create Purchase Order
- get - Get Purchase Order
- update - Update Purchase Order
- delete - Delete Purchase Order
- list - List Subsidiaries
- create - Create Subsidiary
- get - Get Subsidiary
- update - Update Subsidiary
- delete - Delete Subsidiary
- list - List Suppliers
- create - Create Supplier
- get - Get Supplier
- update - Update Supplier
- delete - Delete Supplier
- list - List Tax Rates
- create - Create Tax Rate
- get - Get Tax Rate
- update - Update Tax Rate
- delete - Delete Tax Rate
- list - List Tracking Categories
- create - Create Tracking Category
- get - Get Tracking Category
- update - Update Tracking Category
- delete - Delete Tracking Category
- list - List Applicants
- create - Create Applicant
- get - Get Applicant
- update - Update Applicant
- delete - Delete Applicant
- list - List Applications
- create - Create Application
- get - Get Application
- update - Update Application
- delete - Delete Application
- get - Get API Resource Coverage
- get - Get API Resource
- get - Get Connector Doc content
- get - Get Connector Resource
- list - List activities
- create - Create activity
- get - Get activity
- update - Update activity
- delete - Delete activity
- list - List companies
- create - Create company
- get - Get company
- update - Update company
- delete - Delete company
- list - List contacts
- create - Create contact
- get - Get contact
- update - Update contact
- delete - Delete contact
- list - List opportunities
- create - Create opportunity
- get - Get opportunity
- update - Update opportunity
- delete - Delete opportunity
- list - List pipelines
- get - Get Store
- list - List DriveGroups
- create - Create DriveGroup
- get - Get DriveGroup
- update - Update DriveGroup
- delete - Delete DriveGroup
- list - List Drives
- create - Create Drive
- get - Get Drive
- update - Update Drive
- delete - Delete Drive
- list - List Files
- search - Search Files
- get - Get File
- update - Rename or move File
- delete - Delete File
- download - Download File
- export - Export File
- create - Create Folder
- get - Get Folder
- update - Rename or move Folder
- delete - Delete Folder
- copy - Copy Folder
- list - List SharedLinks
- create - Create Shared Link
- get - Get Shared Link
- update - Update Shared Link
- delete - Delete Shared Link
- create - Start Upload Session
- get - Get Upload Session
- delete - Abort Upload Session
- finish - Finish Upload Session
- list - List Companies
- create - Create Company
- get - Get Company
- update - Update Company
- delete - Delete Company
- list - List Departments
- create - Create Department
- get - Get Department
- update - Update Department
- delete - Delete Department
- list - List Employee Schedules
- list - List Employees
- create - Create Employee
- get - Get Employee
- update - Update Employee
- delete - Delete Employee
- list - List Time Off Requests
- create - Create Time Off Request
- get - Get Time Off Request
- update - Update Time Off Request
- delete - Delete Time Off Request
- list - List Tags
- list - List Comments
- create - Create Comment
- get - Get Comment
- update - Update Comment
- delete - Delete Comment
- list - List Tickets
- create - Create Ticket
- get - Get Ticket
- update - Update Ticket
- delete - Delete Ticket
- list - List Messages
- create - Create Message
- get - Get Message
- update - Update Message
- delete - Delete Message
- list - List connection custom mappings
- list - Get all connections
- get - Get connection
- update - Update connection
- delete - Deletes a connection
- imports - Import connection
- token - Authorize Access Token
- list - Consumer request counts
- create - Create consumer
- list - Get all consumers
- get - Get consumer
- update - Update consumer
- delete - Delete consumer
- state - Create Callback State
- list - Get resource custom fields
- list - List custom mappings
- list - Get all consumer request logs
- create - Create Session
- state - Validate Connection State
- list - List event logs
Some of the endpoints in this SDK support pagination. To use pagination, you make your SDK calls as usual, but the
returned response object will have a Next
method that can be called to pull down the next group of results. If the
return value of Next
is None
, then there are no more pages to be fetched.
Here's an example of one such pagination call:
from apideck_unify import Apideck
import os
with Apideck(
api_key=os.getenv("APIDECK_API_KEY", ""),
consumer_id="test-consumer",
app_id="dSBdXd2H6Mqwfg0atXHXYcysLJE9qyn1VwBtXHX",
) as apideck:
res = apideck.accounting.tax_rates.list(service_id="salesforce", filter_={
"assets": True,
"equity": True,
"expenses": True,
"liabilities": True,
"revenue": True,
}, pass_through={
"search": "San Francisco",
}, fields="id,updated_at")
while res is not None:
# Handle items
res = res.next()
Some of the endpoints in this SDK support retries. If you use the SDK without any configuration, it will fall back to the default retry strategy provided by the API. However, the default retry strategy can be overridden on a per-operation basis, or across the entire SDK.
To change the default retry strategy for a single API call, simply provide a RetryConfig
object to the call:
from apideck_unify import Apideck
from apideck_unify.utils import BackoffStrategy, RetryConfig
import os
with Apideck(
api_key=os.getenv("APIDECK_API_KEY", ""),
consumer_id="test-consumer",
app_id="dSBdXd2H6Mqwfg0atXHXYcysLJE9qyn1VwBtXHX",
) as apideck:
res = apideck.accounting.tax_rates.list(service_id="salesforce", filter_={
"assets": True,
"equity": True,
"expenses": True,
"liabilities": True,
"revenue": True,
}, pass_through={
"search": "San Francisco",
}, fields="id,updated_at",
RetryConfig("backoff", BackoffStrategy(1, 50, 1.1, 100), False))
while res is not None:
# Handle items
res = res.next()
If you'd like to override the default retry strategy for all operations that support retries, you can use the retry_config
optional parameter when initializing the SDK:
from apideck_unify import Apideck
from apideck_unify.utils import BackoffStrategy, RetryConfig
import os
with Apideck(
retry_config=RetryConfig("backoff", BackoffStrategy(1, 50, 1.1, 100), False),
api_key=os.getenv("APIDECK_API_KEY", ""),
consumer_id="test-consumer",
app_id="dSBdXd2H6Mqwfg0atXHXYcysLJE9qyn1VwBtXHX",
) as apideck:
res = apideck.accounting.tax_rates.list(service_id="salesforce", filter_={
"assets": True,
"equity": True,
"expenses": True,
"liabilities": True,
"revenue": True,
}, pass_through={
"search": "San Francisco",
}, fields="id,updated_at")
while res is not None:
# Handle items
res = res.next()
Handling errors in this SDK should largely match your expectations. All operations return a response object or raise an exception.
By default, an API error will raise a models.APIError exception, which has the following properties:
Property | Type | Description |
---|---|---|
.status_code |
int | The HTTP status code |
.message |
str | The error message |
.raw_response |
httpx.Response | The raw HTTP response |
.body |
str | The response content |
When custom error responses are specified for an operation, the SDK may also raise their associated exceptions. You can refer to respective Errors tables in SDK docs for more details on possible exception types for each operation. For example, the list_async
method may raise the following exceptions:
Error Type | Status Code | Content Type |
---|---|---|
models.BadRequestResponse | 400 | application/json |
models.UnauthorizedResponse | 401 | application/json |
models.PaymentRequiredResponse | 402 | application/json |
models.NotFoundResponse | 404 | application/json |
models.UnprocessableResponse | 422 | application/json |
models.APIError | 4XX, 5XX | */* |
from apideck_unify import Apideck, models
import os
with Apideck(
api_key=os.getenv("APIDECK_API_KEY", ""),
consumer_id="test-consumer",
app_id="dSBdXd2H6Mqwfg0atXHXYcysLJE9qyn1VwBtXHX",
) as apideck:
res = None
try:
res = apideck.accounting.tax_rates.list(service_id="salesforce", filter_={
"assets": True,
"equity": True,
"expenses": True,
"liabilities": True,
"revenue": True,
}, pass_through={
"search": "San Francisco",
}, fields="id,updated_at")
while res is not None:
# Handle items
res = res.next()
except models.BadRequestResponse as e:
# handle e.data: models.BadRequestResponseData
raise(e)
except models.UnauthorizedResponse as e:
# handle e.data: models.UnauthorizedResponseData
raise(e)
except models.PaymentRequiredResponse as e:
# handle e.data: models.PaymentRequiredResponseData
raise(e)
except models.NotFoundResponse as e:
# handle e.data: models.NotFoundResponseData
raise(e)
except models.UnprocessableResponse as e:
# handle e.data: models.UnprocessableResponseData
raise(e)
except models.APIError as e:
# handle exception
raise(e)
The default server can also be overridden globally by passing a URL to the server_url: str
optional parameter when initializing the SDK client instance. For example:
from apideck_unify import Apideck
import os
with Apideck(
server_url="https://unify.apideck.com",
api_key=os.getenv("APIDECK_API_KEY", ""),
consumer_id="test-consumer",
app_id="dSBdXd2H6Mqwfg0atXHXYcysLJE9qyn1VwBtXHX",
) as apideck:
res = apideck.accounting.tax_rates.list(service_id="salesforce", filter_={
"assets": True,
"equity": True,
"expenses": True,
"liabilities": True,
"revenue": True,
}, pass_through={
"search": "San Francisco",
}, fields="id,updated_at")
while res is not None:
# Handle items
res = res.next()
The server URL can also be overridden on a per-operation basis, provided a server list was specified for the operation. For example:
from apideck_unify import Apideck
import os
with Apideck(
api_key=os.getenv("APIDECK_API_KEY", ""),
consumer_id="test-consumer",
app_id="dSBdXd2H6Mqwfg0atXHXYcysLJE9qyn1VwBtXHX",
) as apideck:
res = apideck.file_storage.upload_sessions.create(name="Documents", parent_folder_id="1234", size=1810673, service_id="salesforce", drive_id="1234", pass_through=[
{
"service_id": "<id>",
"extend_paths": [
{
"path": "$.nested.property",
"value": {
"TaxClassificationRef": {
"value": "EUC-99990201-V1-00020000",
},
},
},
{
"path": "$.nested.property",
"value": {
"TaxClassificationRef": {
"value": "EUC-99990201-V1-00020000",
},
},
},
],
},
], server_url="https://upload.apideck.com")
assert res.create_upload_session_response is not None
# Handle response
print(res.create_upload_session_response)
The Python SDK makes API calls using the httpx HTTP library. In order to provide a convenient way to configure timeouts, cookies, proxies, custom headers, and other low-level configuration, you can initialize the SDK client with your own HTTP client instance.
Depending on whether you are using the sync or async version of the SDK, you can pass an instance of HttpClient
or AsyncHttpClient
respectively, which are Protocol's ensuring that the client has the necessary methods to make API calls.
This allows you to wrap the client with your own custom logic, such as adding custom headers, logging, or error handling, or you can just pass an instance of httpx.Client
or httpx.AsyncClient
directly.
For example, you could specify a header for every request that this sdk makes as follows:
from apideck_unify import Apideck
import httpx
http_client = httpx.Client(headers={"x-custom-header": "someValue"})
s = Apideck(client=http_client)
or you could wrap the client with your own custom logic:
from apideck_unify import Apideck
from apideck_unify.httpclient import AsyncHttpClient
import httpx
class CustomClient(AsyncHttpClient):
client: AsyncHttpClient
def __init__(self, client: AsyncHttpClient):
self.client = client
async def send(
self,
request: httpx.Request,
*,
stream: bool = False,
auth: Union[
httpx._types.AuthTypes, httpx._client.UseClientDefault, None
] = httpx.USE_CLIENT_DEFAULT,
follow_redirects: Union[
bool, httpx._client.UseClientDefault
] = httpx.USE_CLIENT_DEFAULT,
) -> httpx.Response:
request.headers["Client-Level-Header"] = "added by client"
return await self.client.send(
request, stream=stream, auth=auth, follow_redirects=follow_redirects
)
def build_request(
self,
method: str,
url: httpx._types.URLTypes,
*,
content: Optional[httpx._types.RequestContent] = None,
data: Optional[httpx._types.RequestData] = None,
files: Optional[httpx._types.RequestFiles] = None,
json: Optional[Any] = None,
params: Optional[httpx._types.QueryParamTypes] = None,
headers: Optional[httpx._types.HeaderTypes] = None,
cookies: Optional[httpx._types.CookieTypes] = None,
timeout: Union[
httpx._types.TimeoutTypes, httpx._client.UseClientDefault
] = httpx.USE_CLIENT_DEFAULT,
extensions: Optional[httpx._types.RequestExtensions] = None,
) -> httpx.Request:
return self.client.build_request(
method,
url,
content=content,
data=data,
files=files,
json=json,
params=params,
headers=headers,
cookies=cookies,
timeout=timeout,
extensions=extensions,
)
s = Apideck(async_client=CustomClient(httpx.AsyncClient()))
You can setup your SDK to emit debug logs for SDK requests and responses.
You can pass your own logger class directly into your SDK.
from apideck_unify import Apideck
import logging
logging.basicConfig(level=logging.DEBUG)
s = Apideck(debug_logger=logging.getLogger("apideck_unify"))
You can also enable a default debug logger by setting an environment variable APIDECK_DEBUG
to true.
This SDK is in beta, and there may be breaking changes between versions without a major version update. Therefore, we recommend pinning usage to a specific package version. This way, you can install the same version each time without breaking changes unless you are intentionally looking for the latest version.
While we value open-source contributions to this SDK, this library is generated programmatically. Any manual changes added to internal files will be overwritten on the next generation. We look forward to hearing your feedback. Feel free to open a PR or an issue with a proof of concept and we'll do our best to include it in a future release.