Python Client SDK Generated by Speakeasy.
Project description
apideck-accounting-unify
Developer-friendly & type-safe Python SDK specifically catered to leverage apideck-accounting-unify API.
Summary
Apideck: The Apideck OpenAPI Spec: SDK Optimized
For more information about the API: Apideck Developer Docs
Table of Contents
SDK Installation
[!NOTE] Python version upgrade policy
Once a Python version reaches its official end of life date, a 3-month grace period is provided for users to upgrade. Following this grace period, the minimum python version supported in the SDK will be updated.
The SDK can be installed with either pip or poetry package managers.
PIP
PIP is the default package installer for Python, enabling easy installation and management of packages from PyPI via the command line.
pip install apideck-accounting-unify
Poetry
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-accounting-unify
Shell and script usage with uv
You can use this SDK in a Python shell with uv and the uvx command that comes with it like so:
uvx --from apideck-accounting-unify python
It's also possible to write a standalone Python script without needing to set up a whole project like so:
#!/usr/bin/env -S uv run --script
# /// script
# requires-python = ">=3.9"
# dependencies = [
# "apideck-accounting-unify",
# ]
# ///
from apideck_accounting_unify import Apideck
sdk = Apideck(
# SDK arguments
)
# Rest of script here...
Once that is saved to a file, you can run it with uv run script.py where
script.py can be replaced with the actual file name.
IDE Support
PyCharm
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.
SDK Example Usage
Example
# Synchronous Example
from apideck_accounting_unify import Apideck
import os
with Apideck(
consumer_id="test-consumer",
app_id="dSBdXd2H6Mqwfg0atXHXYcysLJE9qyn1VwBtXHX",
api_key=os.getenv("APIDECK_API_KEY", ""),
) as apideck:
res = apideck.accounting.tax_rates.list(raw=False, service_id="salesforce", limit=20, 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_accounting_unify import Apideck
import asyncio
import os
async def main():
async with Apideck(
consumer_id="test-consumer",
app_id="dSBdXd2H6Mqwfg0atXHXYcysLJE9qyn1VwBtXHX",
api_key=os.getenv("APIDECK_API_KEY", ""),
) as apideck:
res = await apideck.accounting.tax_rates.list_async(raw=False, service_id="salesforce", limit=20, 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())
Authentication
Per-Client Security Schemes
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_accounting_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(raw=False, service_id="salesforce", limit=20, 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 Resources and Operations
Available methods
accounting
accounting.aged_creditors
- get - Get Aged Creditors
accounting.aged_debtors
- get - Get Aged Debtors
accounting.attachments
- list - List Attachments
- upload - Upload attachment
- get - Get Attachment
- delete - Delete Attachment
- download - Download Attachment
accounting.balance_sheet
- get - Get BalanceSheet
accounting.bank_feed_accounts
- list - List Bank Feed Accounts
- create - Create Bank Feed Account
- get - Get Bank Feed Account
- update - Update Bank Feed Account
- delete - Delete Bank Feed Account
accounting.bank_feed_statements
- list - List Bank Feed Statements
- create - Create Bank Feed Statement
- get - Get Bank Feed Statement
- update - Update Bank Feed Statement
- delete - Delete Bank Feed Statement
accounting.bill_payments
- list - List Bill Payments
- create - Create Bill Payment
- get - Get Bill Payment
- update - Update Bill Payment
- delete - Delete Bill Payment
accounting.bills
accounting.company_info
- get - Get company info
accounting.credit_notes
- list - List Credit Notes
- create - Create Credit Note
- get - Get Credit Note
- update - Update Credit Note
- delete - Delete Credit Note
accounting.customers
- list - List Customers
- create - Create Customer
- get - Get Customer
- update - Update Customer
- delete - Delete Customer
accounting.departments
- list - List Departments
- create - Create Department
- get - Get Department
- update - Update Department
- delete - Delete Department
accounting.expenses
- list - List Expenses
- create - Create Expense
- get - Get Expense
- update - Update Expense
- delete - Delete Expense
accounting.invoice_items
- list - List Invoice Items
- create - Create Invoice Item
- get - Get Invoice Item
- update - Update Invoice Item
- delete - Delete Invoice Item
accounting.invoices
- list - List Invoices
- create - Create Invoice
- get - Get Invoice
- update - Update Invoice
- delete - Delete Invoice
accounting.journal_entries
- list - List Journal Entries
- create - Create Journal Entry
- get - Get Journal Entry
- update - Update Journal Entry
- delete - Delete Journal Entry
accounting.ledger_accounts
- list - List Ledger Accounts
- create - Create Ledger Account
- get - Get Ledger Account
- update - Update Ledger Account
- delete - Delete Ledger Account
accounting.locations
- list - List Locations
- create - Create Location
- get - Get Location
- update - Update Location
- delete - Delete Location
accounting.payments
- list - List Payments
- create - Create Payment
- get - Get Payment
- update - Update Payment
- delete - Delete Payment
accounting.profit_and_loss
- get - Get Profit and Loss
accounting.purchase_orders
- list - List Purchase Orders
- create - Create Purchase Order
- get - Get Purchase Order
- update - Update Purchase Order
- delete - Delete Purchase Order
accounting.subsidiaries
- list - List Subsidiaries
- create - Create Subsidiary
- get - Get Subsidiary
- update - Update Subsidiary
- delete - Delete Subsidiary
accounting.suppliers
- list - List Suppliers
- create - Create Supplier
- get - Get Supplier
- update - Update Supplier
- delete - Delete Supplier
accounting.tax_rates
- list - List Tax Rates
- create - Create Tax Rate
- get - Get Tax Rate
- update - Update Tax Rate
- delete - Delete Tax Rate
accounting.tracking_categories
- list - List Tracking Categories
- create - Create Tracking Category
- get - Get Tracking Category
- update - Update Tracking Category
- delete - Delete Tracking Category
vault
vault.connection_custom_mappings
- list - List connection custom mappings
vault.connection_settings
vault.connections
- list - Get all connections
- get - Get connection
- update - Update connection
- delete - Deletes a connection
- imports - Import connection
- token - Authorize Access Token
vault.consumer_request_counts
- list - Consumer request counts
vault.consumers
- create - Create consumer
- list - Get all consumers
- get - Get consumer
- update - Update consumer
- delete - Delete consumer
vault.create_callback
- state - Create Callback State
vault.custom_fields
- list - Get resource custom fields
vault.custom_mappings
- list - List custom mappings
vault.logs
- list - Get all consumer request logs
vault.sessions
- create - Create Session
vault.validate_connection
- state - Validate Connection State
Pagination
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_accounting_unify import Apideck
import os
with Apideck(
consumer_id="test-consumer",
app_id="dSBdXd2H6Mqwfg0atXHXYcysLJE9qyn1VwBtXHX",
api_key=os.getenv("APIDECK_API_KEY", ""),
) as apideck:
res = apideck.accounting.tax_rates.list(raw=False, service_id="salesforce", limit=20, 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()
File uploads
Certain SDK methods accept file objects as part of a request body or multi-part request. It is possible and typically recommended to upload files as a stream rather than reading the entire contents into memory. This avoids excessive memory consumption and potentially crashing with out-of-memory errors when working with very large files. The following example demonstrates how to attach a file stream to a request.
[!TIP]
For endpoints that handle file uploads bytes arrays can also be used. However, using streams is recommended for large files.
import apideck_accounting_unify
from apideck_accounting_unify import Apideck
import os
with Apideck(
consumer_id="test-consumer",
app_id="dSBdXd2H6Mqwfg0atXHXYcysLJE9qyn1VwBtXHX",
api_key=os.getenv("APIDECK_API_KEY", ""),
) as apideck:
res = apideck.accounting.attachments.upload(reference_type=apideck_accounting_unify.AttachmentReferenceType.INVOICE, reference_id="123456", request_body=open("example.file", "rb"), raw=False, x_apideck_metadata="{\"name\":\"document.pdf\",\"description\":\"Invoice attachment\"}", service_id="salesforce")
assert res.create_attachment_response is not None
# Handle response
print(res.create_attachment_response)
Retries
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_accounting_unify import Apideck
from apideck_accounting_unify.utils import BackoffStrategy, RetryConfig
import os
with Apideck(
consumer_id="test-consumer",
app_id="dSBdXd2H6Mqwfg0atXHXYcysLJE9qyn1VwBtXHX",
api_key=os.getenv("APIDECK_API_KEY", ""),
) as apideck:
res = apideck.accounting.tax_rates.list(raw=False, service_id="salesforce", limit=20, 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_accounting_unify import Apideck
from apideck_accounting_unify.utils import BackoffStrategy, RetryConfig
import os
with Apideck(
retry_config=RetryConfig("backoff", BackoffStrategy(1, 50, 1.1, 100), False),
consumer_id="test-consumer",
app_id="dSBdXd2H6Mqwfg0atXHXYcysLJE9qyn1VwBtXHX",
api_key=os.getenv("APIDECK_API_KEY", ""),
) as apideck:
res = apideck.accounting.tax_rates.list(raw=False, service_id="salesforce", limit=20, 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()
Error Handling
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 | */* |
Example
from apideck_accounting_unify import Apideck, models
import os
with Apideck(
consumer_id="test-consumer",
app_id="dSBdXd2H6Mqwfg0atXHXYcysLJE9qyn1VwBtXHX",
api_key=os.getenv("APIDECK_API_KEY", ""),
) as apideck:
res = None
try:
res = apideck.accounting.tax_rates.list(raw=False, service_id="salesforce", limit=20, 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)
Server Selection
Override Server URL Per-Client
The default server can be overridden globally by passing a URL to the server_url: str optional parameter when initializing the SDK client instance. For example:
from apideck_accounting_unify import Apideck
import os
with Apideck(
server_url="https://unify.apideck.com",
consumer_id="test-consumer",
app_id="dSBdXd2H6Mqwfg0atXHXYcysLJE9qyn1VwBtXHX",
api_key=os.getenv("APIDECK_API_KEY", ""),
) as apideck:
res = apideck.accounting.tax_rates.list(raw=False, service_id="salesforce", limit=20, 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()
Override Server URL Per-Operation
The server URL can also be overridden on a per-operation basis, provided a server list was specified for the operation. For example:
import apideck_accounting_unify
from apideck_accounting_unify import Apideck
import os
with Apideck(
consumer_id="test-consumer",
app_id="dSBdXd2H6Mqwfg0atXHXYcysLJE9qyn1VwBtXHX",
api_key=os.getenv("APIDECK_API_KEY", ""),
) as apideck:
res = apideck.accounting.attachments.upload(reference_type=apideck_accounting_unify.AttachmentReferenceType.INVOICE, reference_id="123456", request_body=open("example.file", "rb"), raw=False, x_apideck_metadata="{\"name\":\"document.pdf\",\"description\":\"Invoice attachment\"}", service_id="salesforce", server_url="https://upload.apideck.com")
assert res.create_attachment_response is not None
# Handle response
print(res.create_attachment_response)
Custom HTTP Client
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_accounting_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_accounting_unify import Apideck
from apideck_accounting_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()))
Resource Management
The Apideck class implements the context manager protocol and registers a finalizer function to close the underlying sync and async HTTPX clients it uses under the hood. This will close HTTP connections, release memory and free up other resources held by the SDK. In short-lived Python programs and notebooks that make a few SDK method calls, resource management may not be a concern. However, in longer-lived programs, it is beneficial to create a single SDK instance via a context manager and reuse it across the application.
from apideck_accounting_unify import Apideck
import os
def main():
with Apideck(
consumer_id="test-consumer",
app_id="dSBdXd2H6Mqwfg0atXHXYcysLJE9qyn1VwBtXHX",
api_key=os.getenv("APIDECK_API_KEY", ""),
) as apideck:
# Rest of application here...
# Or when using async:
async def amain():
async with Apideck(
consumer_id="test-consumer",
app_id="dSBdXd2H6Mqwfg0atXHXYcysLJE9qyn1VwBtXHX",
api_key=os.getenv("APIDECK_API_KEY", ""),
) as apideck:
# Rest of application here...
Debugging
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_accounting_unify import Apideck
import logging
logging.basicConfig(level=logging.DEBUG)
s = Apideck(debug_logger=logging.getLogger("apideck_accounting_unify"))
You can also enable a default debug logger by setting an environment variable APIDECK_DEBUG to true.
Development
Maturity
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.
Contributions
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.
SDK Created by Speakeasy
Project details
Release history Release notifications | RSS feed
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 apideck_accounting_unify-0.16.2.tar.gz.
File metadata
- Download URL: apideck_accounting_unify-0.16.2.tar.gz
- Upload date:
- Size: 236.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.3 CPython/3.9.22 Linux/6.8.0-1027-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b6227d004e6f1bcd481b9d7be59ccf9e62e6127a55daf087995beaf0490094d9
|
|
| MD5 |
37f91674c16ff1986fc243935b170cab
|
|
| BLAKE2b-256 |
b6956dba80d76df875f75d22a98f7970a16e7558a70eafb6dd44257388ece318
|
File details
Details for the file apideck_accounting_unify-0.16.2-py3-none-any.whl.
File metadata
- Download URL: apideck_accounting_unify-0.16.2-py3-none-any.whl
- Upload date:
- Size: 665.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.3 CPython/3.9.22 Linux/6.8.0-1027-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3157ff1e78fcf6f5852fe32d40fd308edada44d4313048675f66c57ffe996156
|
|
| MD5 |
06485be36f49f082cb7c7fb5b6bfe17c
|
|
| BLAKE2b-256 |
4ff6335c8f129790f503944437c67e76e33341d706e14b7068c9128a845d91c5
|