Skip to main content

No project description provided

Project description

Merge Python Library

fern shield pypi

The Merge Python library provides convenient access to the Merge APIs from Python.

Table of Contents

Documentation

API reference documentation is available here.

Installation

pip install MergePythonClient

Reference

A full reference for this library is available here.

Usage

Instantiate and use the client with the following:

from merge import Merge
from merge.resources.chat import DataPassthroughRequest, MethodEnum

client = Merge(
    account_token="YOUR_ACCOUNT_TOKEN",
    api_key="YOUR_API_KEY",
)
client.chat.async_passthrough.create(
    request=DataPassthroughRequest(
        method=MethodEnum.GET,
        path="/scooters",
    ),
)

Instantiation

import merge
from merge.client import Merge

client = Merge(api_key="YOUR_API_KEY", account_token="YOUR_ACCOUNT_TOKEN")

Categories

This SDK contains the ATS, HRIS, CRM, Ticketing, Accounting, and File Storage categories. Even if you do not plan on using more than one Merge API category right now, the SDK provides upgrade-flexibility in case you find new Merge API categories useful in the future.

Each category is namespaced:

client = Merge(api_key="YOUR_API_KEY")

client.ats. # APIs specific to the ATS Category

client.hris. # APIs specific to the HRIS Category

Async Client

The SDK also exports an async client so that you can make non-blocking calls to our API.

import asyncio

from merge import AsyncMerge
from merge.resources.chat import DataPassthroughRequest, MethodEnum

client = AsyncMerge(
    account_token="YOUR_ACCOUNT_TOKEN",
    api_key="YOUR_API_KEY",
)


async def main() -> None:
    await client.chat.async_passthrough.create(
        request=DataPassthroughRequest(
            method=MethodEnum.GET,
            path="/scooters",
        ),
    )


asyncio.run(main())

Exception Handling

When the API returns a non-success status code (4xx or 5xx response), a subclass of the following error will be thrown.

from merge.core.api_error import ApiError

try:
    client.chat.async_passthrough.create(...)
except ApiError as e:
    print(e.status_code)
    print(e.body)

Advanced

Access Raw Response Data

The SDK provides access to raw response data, including headers, through the .with_raw_response property. The .with_raw_response property returns a "raw" client that can be used to access the .headers and .data attributes.

from merge import Merge

client = Merge(
    ...,
)
response = client.chat.async_passthrough.with_raw_response.create(...)
print(response.headers)  # access the response headers
print(response.data)  # access the underlying object

Retries

The SDK is instrumented with automatic retries with exponential backoff. A request will be retried as long as the request is deemed retryable and the number of retry attempts has not grown larger than the configured retry limit (default: 2).

A request is deemed retryable when any of the following HTTP status codes is returned:

  • 408 (Timeout)
  • 429 (Too Many Requests)
  • 5XX (Internal Server Errors)

Use the max_retries request option to configure this behavior.

client.chat.async_passthrough.create(..., request_options={
    "max_retries": 1
})

Timeouts

The SDK defaults to a 60 second timeout. You can configure this with a timeout option at the client or request level.

from merge import Merge

client = Merge(
    ...,
    timeout=20.0,
)


# Override timeout for a specific method
client.chat.async_passthrough.create(..., request_options={
    "timeout_in_seconds": 1
})

Custom Client

You can override the httpx client to customize it for your use-case. Some common use-cases include support for proxies and transports.

import httpx
from merge import Merge

client = Merge(
    ...,
    httpx_client=httpx.Client(
        proxy="http://my.test.proxy.example.com",
        transport=httpx.HTTPTransport(local_address="0.0.0.0"),
    ),
)

Contributing

While we value open-source contributions to this SDK, this library is generated programmatically. Additions made directly to this library would have to be moved over to our generation code, otherwise they would be overwritten upon the next generated release. Feel free to open a PR as a proof of concept, but know that we will not be able to merge it as-is. We suggest opening an issue first to discuss with us!

On the other hand, contributions to the README are always very welcome!

File Download

import merge
from merge.client import Merge

merge_client = Merge(
    api_key="<YOUR_API_KEY>", 
    account_token="<YOUR_ACCOUNT_TOKEN>")

files = merge_client.filestorage.files.list(name="<FILE_NAME>").results

id = files[0].id
name = files[0].name
local_filename = f"<LOCAL_FILE_PATH>/{name}"

response = merge_client.filestorage.files.download_retrieve(id=id)
with open(local_filename, "wb") as f:
    for chunk in response:
        f.write(chunk)

Pagination

The SDK may return paginated results. Endpoints that return paginated results will include a next and prev property on the response. To get the next page, you can pass in the value of next to the cursor property on the request. Similarly, to get the previous page, you can pass in the value of prev to the cursor property on the request.

Below is an example of iterating over all pages:

# response contains the first page
response = merge_client.hris.employees.list(created_after="2030-01-01")

# if there is a next page, load it by passing `next` to the cursor argument
while response.next is not None:
    response = hris_client.employees.list(
        cursor=response.next, 
        created_after="2030-01-01")

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mergepythonclient-2.6.3.tar.gz (1.2 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mergepythonclient-2.6.3-py3-none-any.whl (2.7 MB view details)

Uploaded Python 3

File details

Details for the file mergepythonclient-2.6.3.tar.gz.

File metadata

  • Download URL: mergepythonclient-2.6.3.tar.gz
  • Upload date:
  • Size: 1.2 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.5.1 CPython/3.8.18 Linux/6.17.0-1010-azure

File hashes

Hashes for mergepythonclient-2.6.3.tar.gz
Algorithm Hash digest
SHA256 de6e92c22a2daf25ff64150823ffafeb5a342db9e1ea5dc08f52b26f68d8b055
MD5 22f0ad92ebbe8585d745449e55ceb690
BLAKE2b-256 215453ccd1c3a6025564be30aeb6d2d05b944e8e784db9de06578ae06b65be62

See more details on using hashes here.

File details

Details for the file mergepythonclient-2.6.3-py3-none-any.whl.

File metadata

  • Download URL: mergepythonclient-2.6.3-py3-none-any.whl
  • Upload date:
  • Size: 2.7 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.5.1 CPython/3.8.18 Linux/6.17.0-1010-azure

File hashes

Hashes for mergepythonclient-2.6.3-py3-none-any.whl
Algorithm Hash digest
SHA256 d27a63846031528a9404d5cc2ba3df9b0cf2024fa49345989fbc626efe2c9e6b
MD5 98135e1bf3cce136e39a278b8ff29251
BLAKE2b-256 fa2be9712b65ba356bffe2617b8a0075deb1563102f1215e5f46492e3a039a59

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page