项目作者: dnsimple

项目描述 :
The DNSimple API client for Python.
高级语言: Python
项目地址: git://github.com/dnsimple/dnsimple-python.git
创建时间: 2010-10-08T16:53:43Z
项目社区:https://github.com/dnsimple/dnsimple-python

开源协议:MIT License

下载


DNSimple Python Client

A Python client for the DNSimple API v2.

CI

Documentation

Requirements

  • Python 3.12+ - Note later versions of Python may be supported, but we make no guarantees as they are not tracked in our CI.

Installation

Where <version> denotes the version of the client you want to install.

To install the latest version:

  1. pip install dnsimple

To install a specific version:

  1. pip install dnsimple==2.0.1

Usage

This library is a Python client you can use to interact with the DNSimple API v2. Here are some examples.

  1. from dnsimple import Client
  2. client = Client(access_token='a1b2c3')
  3. # Fetch your details
  4. response = client.identity.whoami() # execute the call
  5. data = response.data # extract the relevant data from the response or
  6. account = client.identity.whoami().data.account # execute the call and get the data in one line

Sandbox Environment

We highly recommend testing against our sandbox environment before using our
production environment. This will allow you to avoid real purchases, live charges on your credit card, and reduce the
chance of your running up against rate limits.

The client supports both the production and sandbox environment. To switch to sandbox pass the sandbox API host using
the base_url option when you construct the client:

  1. from dnsimple import Client
  2. client = Client(base_url='https://api.sandbox.dnsimple.com', access_token="a1b2c3")

You can also set the sandbox environment like so:

  1. from dnsimple import Client
  2. client = Client(sandbox=True, access_token='a1b2c3')

You will need to ensure that you are using an access token created in the sandbox environment.
Production tokens will not work in the sandbox environment.

Define an account ID

  1. from dnsimple import Client
  2. client = Client(access_token='a1b2c3')
  3. account_id = 1010
  4. # You can also fetch it from the whoami response
  5. # as long as you authenticate with an Account access token
  6. whoami = client.identity.whoami().data
  7. account_id = whoami.account.id

List your domains

  1. from dnsimple import Client
  2. client = Client(access_token='a1b2c3')
  3. account_id = client.identity.whoami().data.account.id
  4. domains = client.domains.list_domains(account_id).data # Domains from the 1010 account (first page)
  5. client.domains.list_domains(account_id, sort='expires_on:asc').data # Domains from the 1010 account in ascending order by domain expiration date
  6. client.domains.list_domains(account_id, filter={'name_like': 'example'}).data # Domains from the 1010 account filtered by the domain name name

Create a domain

  1. from dnsimple import Client
  2. client = Client(access_token='a1b2c3')
  3. account_id = client.identity.whoami().data.account.id
  4. response = client.domains.create_domain(account_id, 'example.com')
  5. domain = response.data # The newly created domain

Get a domain

  1. from dnsimple import Client
  2. client = Client(access_token='a1b2c3')
  3. account_id = client.identity.whoami().data.account.id
  4. domain_id = client.domains.list_domains(account_id).data[0].id
  5. domain = client.domains.get_domain(account_id, domain_id).data # The domain you are looking for

Setting a custom User-Agent header

You customize the User-Agent header for the calls made to the DNSimple API:

  1. from dnsimple import Client
  2. client = Client(user_agent="my-app")

The value you provide will be appended to the default User-Agent the client uses.
For example, if you use my-app, the final header value will be my-app dnsimple-python/0.1.0 (note that it will vary depending on the client version).

Contributing

Contibutions are welcomed. Please open an issue to discuss the changes before opening a PR. For more details on how to do development please refer to CONTRIBUTING.md

License

Copyright (c) 2024 DNSimple Corporation. This is Free Software distributed under the MIT license.