Domains

Domain

class doapi.Domain[source]

A domain resource, representing a domain name whose DNS is managed by DigitalOcean’s nameservers.

New domains are created via the doapi.create_domain() method and can be retrieved with the doapi.fetch_domain() and doapi.fetch_all_domains() methods.

The DigitalOcean API specifies the following fields for domain objects:

Variables:
  • name (string) – the domain name
  • ttl (number) – the time-to-live for the domain’s records, in seconds
  • zone_file (string) – the complete zone file for the domain
__str__()[source]

Convert the domain to just the actual domain name

url

The endpoint for general operations on the individual domain

fetch()[source]

Fetch & return a new Domain object representing the domain’s current state

Return type:Domain
Raises:DOAPIError – if the API endpoint replies with an error (e.g., if the domain no longer exists)
delete()[source]

Delete the domain

Returns:None
Raises:DOAPIError – if the API endpoint replies with an error
record_url

The endpoint for operations on the domain’s DNS records

fetch_record(obj)[source]

Fetch a domain record by ID number

Parameters:obj (integer, dict, or DomainRecord) – the ID of the record, a dict with an "id" field, or a DomainRecord object (to re-fetch the same record)
Return type:DomainRecord
Raises:DOAPIError – if the API endpoint replies with an error
fetch_all_records()[source]

Returns a generator that yields all of the DNS records for the domain

Return type:generator of DomainRecords
Raises:DOAPIError – if the API endpoint replies with an error
create_record(type, name, data, priority=None, port=None, weight=None, **kwargs)[source]

Add a new DNS record to the domain

Parameters:
  • type (str) – the type of DNS record to add ("A", "CNAME", etc.)
  • name (str) – the name (hostname, alias, etc.) of the new record
  • data (str) – the value of the new record
  • priority (int) – the priority of the new record (SRV and MX records only)
  • port (int) – the port that the service is accessible on (SRV records only)
  • weight (int) – the weight of records with the same priority (SRV records only)
  • kwargs – additional fields to include in the API request
Returns:

the new domain record

Return type:

DomainRecord

Raises:

DOAPIError – if the API endpoint replies with an error

DomainRecord

class doapi.DomainRecord[source]

A domain record resource, representing an individual DNS record that can be set & modified by the user of the DigitalOcean API.

New domain records are created via the Domain.create_record() method and can be retrieved with the Domain.fetch_record() and Domain.fetch_all_records() methods.

The DigitalOcean API specifies the following fields for domain record objects:

Variables:
  • id (int) – a unique identifier for the domain record
  • type (string) – the type of the DNS record
  • name (string) – the name of the DNS record
  • data (string) – the value of the DNS record
  • priority (number or None) – the priority of the record (SRV and MX records only)
  • port (number or None) – the port of the record (SRV records only)
  • weight (number or None) – the weight of the record (SRV records only)
domain

The Domain to which the record belongs

__int__()

Convert the resource to its unique integer ID

url

The endpoint for general operations on the individual domain record

fetch()[source]

Fetch & return a new DomainRecord object representing the domain record’s current state

Return type:DomainRecord
Raises:DOAPIError – if the API endpoint replies with an error (e.g., if the domain record no longer exists)
fetch_domain()[source]

Fetch & return the domain resource that the record belongs to

Return type:Domain
Raises:DOAPIError – if the API endpoint replies with an error
update_record(**attrs)[source]

Update the record, modifying any number of its attributes (except id). update_record takes the same keyword arguments as Domain.create_record(); pass in only those attributes that you want to update.

Returns:an updated DomainRecord object
Return type:DomainRecord
Raises:DOAPIError – if the API endpoint replies with an error
delete()[source]

Delete the domain record

Returns:None
Raises:DOAPIError – if the API endpoint replies with an error