Skip to main content

Python Client SDK

Project description

Ding Python SDK

The Ding Python library provides convenient access to the Ding API from applications written in the Python language.

Summary

Ding: The OTP API allows you to send authentication codes to your users using their phone numbers.

Table of Contents

SDK Installation

The SDK can be installed using the pip package manager, with dependencies and metadata stored in the setup.py file.

pip install ding_api_client

SDK Example Usage

SDK Example Usage

Send a code

Send an OTP code to a user's phone number.

import ding
from ding.models import components

s = ding.Ding(
    api_key="YOUR_API_KEY",
)


res = s.otp.create_authentication(request=components.CreateAuthenticationRequest(
    customer_uuid='c9f826e0-deca-41ec-871f-ecd6e8efeb46',
    phone_number='+1234567890',
    locale='fr-FR',
))

if res.create_authentication_response is not None:
    # handle response
    pass

Check a code

Check that a code entered by a user is valid.

import ding
from ding.models import components

s = ding.Ding(
    api_key="YOUR_API_KEY",
)


res = s.otp.check(request=components.CreateCheckRequest(
    customer_uuid='e0e7b0e9-739d-424b-922f-1c2cb48ab077',
    authentication_uuid='8f1196d5-806e-4b71-9b24-5f96ec052808',
    check_code='123456',
))

if res.create_check_response is not None:
    # handle response
    pass

Perform a retry

Perform a retry if a user has not received the code.

import ding

s = ding.Ding(
    api_key="YOUR_API_KEY",
)


res = s.otp.retry()

if res.retry_authentication_response is not None:
    # handle response
    pass

Send feedback

Send feedback about the authentication process.

import ding
from ding.models import components

s = ding.Ding(
    api_key="YOUR_API_KEY",
)


res = s.otp.feedback(request=components.FeedbackRequest(
    customer_uuid='c0c405fa-6bcb-4094-9430-7d6e2428ff23',
    phone_number='+1234567890',
    status=components.FeedbackRequestStatus.ONBOARDED,
))

if res.feedback_response is not None:
    # handle response
    pass

Get authentication status

Get the status of an authentication.

import ding

s = ding.Ding(
    api_key="YOUR_API_KEY",
)


res = s.otp.get_authentication_status(auth_uuid='d8446450-f2fa-4dd9-806b-df5b8c661f23')

if res.authentication_status_response is not None:
    # handle response
    pass

Look up for phone number

Perform a phone number lookup.

import ding

s = ding.Ding(
    api_key="YOUR_API_KEY",
)


res = s.lookup.lookup(phone_number='<value>', customer_uuid='6e93aa15-9177-4d09-8395-b69ce50db1c8')

if res.lookup_response is not None:
    # handle response
    pass

Available Resources and Operations

Available methods

lookup

  • lookup - Look up for phone number

otp

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 errors.SDKError 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 exception. You can refer to respective Errors tables in SDK docs for more details on possible exception types for each operation. For example, the create_authentication method may raise the following exceptions:

Error Type Status Code Content Type
errors.SDKError 4XX, 5XX */*

Example

import ding
from ding.models import components, errors

s = ding.Ding(
    api_key="YOUR_API_KEY",
)

res = None
try:
    res = s.otp.create_authentication(request=components.CreateAuthenticationRequest(
    customer_uuid='c9f826e0-deca-41ec-871f-ecd6e8efeb46',
    phone_number='+1234567890',
    locale='fr-FR',
))

except errors.SDKError as e:
    # handle exception
    raise(e)

if res.create_authentication_response is not None:
    # handle response
    pass

Server Selection

Select Server by Index

You can override the default server globally by passing a server index to the server_idx: int optional parameter when initializing the SDK client instance. The selected server will then be used as the default on the operations that use it. This table lists the indexes associated with the available servers:

# Server Variables
0 https://api.ding.live/v1 None

Example

import ding
from ding.models import components

s = ding.Ding(
    server_idx=0,
    api_key="YOUR_API_KEY",
)


res = s.otp.create_authentication(request=components.CreateAuthenticationRequest(
    customer_uuid='c9f826e0-deca-41ec-871f-ecd6e8efeb46',
    phone_number='+1234567890',
    locale='fr-FR',
))

if res.create_authentication_response is not None:
    # handle response
    pass

Override Server URL Per-Client

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:

import ding
from ding.models import components

s = ding.Ding(
    server_url="https://api.ding.live/v1",
    api_key="YOUR_API_KEY",
)


res = s.otp.create_authentication(request=components.CreateAuthenticationRequest(
    customer_uuid='c9f826e0-deca-41ec-871f-ecd6e8efeb46',
    phone_number='+1234567890',
    locale='fr-FR',
))

if res.create_authentication_response is not None:
    # handle response
    pass

Custom HTTP Client

The Python SDK makes API calls using the requests 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 a custom requests.Session object.

For example, you could specify a header for every request that this sdk makes as follows:

import ding
import requests

http_client = requests.Session()
http_client.headers.update({'x-custom-header': 'someValue'})
s = ding.Ding(client=http_client)

Authentication

Per-Client Security Schemes

This SDK supports the following security scheme globally:

Name Type Scheme
api_key apiKey API key

To authenticate with the API the api_key parameter must be set when initializing the SDK client instance. For example:

import ding
from ding.models import components

s = ding.Ding(
    api_key="YOUR_API_KEY",
)


res = s.otp.create_authentication(request=components.CreateAuthenticationRequest(
    customer_uuid='c9f826e0-deca-41ec-871f-ecd6e8efeb46',
    phone_number='+1234567890',
    locale='fr-FR',
))

if res.create_authentication_response is not None:
    # handle response
    pass

Development

Contributions

While we value open-source contributions to this SDK, this library is generated programmatically. Feel free to open a PR or a Github issue as a proof of concept and we'll do our best to include it in a future release!

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

ding_api_client-3.9.1.tar.gz (26.9 kB view details)

Uploaded Source

Built Distribution

ding_api_client-3.9.1-py3-none-any.whl (37.0 kB view details)

Uploaded Python 3

File details

Details for the file ding_api_client-3.9.1.tar.gz.

File metadata

  • Download URL: ding_api_client-3.9.1.tar.gz
  • Upload date:
  • Size: 26.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.8.18

File hashes

Hashes for ding_api_client-3.9.1.tar.gz
Algorithm Hash digest
SHA256 977af236a6583172cb444324f193b781b106db6401d0c61560660b86992cc0b8
MD5 57a4fedfcb3e552c83f62c3b72867093
BLAKE2b-256 bad1aa97dd315c60c5870112938c6dfbbbf3c37f8318e60704c53638832eafe5

See more details on using hashes here.

File details

Details for the file ding_api_client-3.9.1-py3-none-any.whl.

File metadata

File hashes

Hashes for ding_api_client-3.9.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c1f319c5bfacbfc0a4e457c0f277e1e2fe6eeeaa9ce6dd7511218f60fbe2f1dd
MD5 1b93e86edcc58489a9e5cb21f89e129f
BLAKE2b-256 6b77abb37ab01a72f73aea1ef48f3678e974ea246ec74d58f9f6b72d8007d00c

See more details on using hashes here.

Supported by

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