Skip to main content

A Python SDK to wrap Rebrandly's API

Project description

Python SDK

For our official developer documentation, visit our developer site

Description

This repository is a Python SDK that wraps the Rebrandly API.

Installation

pip install rebrandly-official

Local Development and Testing

Create a .env.development or .env.test file with the below code and populate the values:

API_KEY='YOUR_API_KEY'
EXTENDED_WORKSPACE_ID='YOUR_EXTENDED_WORKSPACE_ID'
EXTENDED_WORKSPACE_DOMAIN_ID='YOUR_EXTENDED_WORKSPACE_DOMAIN_ID'
IOS_APP_ID='YOUR_IOS_APP_ID'
ANDROID_APP_ID='YOUR_ANDROID_APP_ID'

Export your ENVIRONMENT variable before running tests so test files know which .env file to load. If the ENVIRONMENT variable is not specified, the default file to be loaded is .env.development.

Authentication

This SDK supports authentication via API key. You can create an API key in your Rebrandly dashboard. The API key should be specified when creating a RebrandlyClient instance.

from rebrandly_official.rebrandly_client import RebrandlyClient

client = RebrandlyClient('YOUR_API_KEY')

Usage

Create a link:

client = RebrandlyClient('YOUR_API_KEY')
new_link = client.links.create('https://destination_url_...')

Create conditional traffic routing rule:

link_id = client.links.create('https://www.rebrandly.com')['id']
route = {
    "destination":'https://www.rebrandly.com/enterprise-security',
    "condition":
        {"and":[{"property":"req.country","operator":"in","values":["ie"]}]}
    }
client.links.create_route(link_id, route)

Create link OpenGraph:

link_id = client.links.create(destination_url_google)['id']
client.links.set_opengraph(link_id, 'What is Rebrandly', image_url='https://rebrandly.com/example.jpg', object_type='website')

Create deep link:

link_id = client.links.create('https://wwww.rebrandly.com')['id']
path = {"path":"/watch?apex=&ios_scheme=&v=3VmtibKpmXI"}
client.links.create_deep_link(link_id, 'YOUR-APP-ID-HERE', path)

Pagination

This SDK supports pagination for requests that return many results. When a method that supports pagination is called, a PaginatedResponse instance will be returned. A PaginatedResponse is an iterable object that supports a next() function to retrieve the next batch of results. Here is a code snippet for how to work with a method that supports pagination. In the example below, it will list all links and aggregate those links into an array called all_links.

    page_of_links = client.links.list()
    all_links = []
    while page_of_links.current_links_count > 0:
        for link in page_of_links:
            all_links.append(link)
        page_of_links.next()

Design Patterns

Create and Update vs Set

Create methods will create a new resource. Update methods will update an existing resource. Set methods will create a resource or overwrite the existing resource if one already exists.

License

Rebrandly Python SDK is released under the MIT License.

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

rebrandly_official-0.0.2.tar.gz (9.4 kB view details)

Uploaded Source

Built Distribution

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

rebrandly_official-0.0.2-py3-none-any.whl (8.9 kB view details)

Uploaded Python 3

File details

Details for the file rebrandly_official-0.0.2.tar.gz.

File metadata

  • Download URL: rebrandly_official-0.0.2.tar.gz
  • Upload date:
  • Size: 9.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.6

File hashes

Hashes for rebrandly_official-0.0.2.tar.gz
Algorithm Hash digest
SHA256 860d036491dedd6d966e2cd6d10684c4a832e19f88297ad7ed6e913bc31a5929
MD5 68a5907be350759777579caa81c4602a
BLAKE2b-256 e42c3d6a2ef2c9a0cd8ba16dcbd128ffd8ee976294163b7b3c37352c694cc6c6

See more details on using hashes here.

File details

Details for the file rebrandly_official-0.0.2-py3-none-any.whl.

File metadata

File hashes

Hashes for rebrandly_official-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 4efb50c44e4d3a72e8926be808a044611313a31105c6fc76df9f98f08a971403
MD5 60ec1200ff29916801fdff47985db175
BLAKE2b-256 b3359fbab47e546e5aef1aeb633d79a0a04e549416118c469cf9d2d488743be0

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