📝 DNS¶
DNS record management operations and types.
🚀 Quick Examples¶
List All Records¶
from oinker import AsyncPiglet
async with AsyncPiglet() as piglet:
records = await piglet.dns.list("example.com")
for record in records:
print(f"{record.record_type} {record.name} -> {record.content}")
Get a Single Record by ID¶
async with AsyncPiglet() as piglet:
record = await piglet.dns.get("example.com", record_id="123456")
print(f"{record.record_type} {record.name} -> {record.content}")
Get Records by Name and Type¶
async with AsyncPiglet() as piglet:
# Get all A records for www subdomain
records = await piglet.dns.get_by_name_type(
"example.com",
record_type="A",
subdomain="www"
)
for record in records:
print(f"{record.name} -> {record.content}")
# Get root domain A records (no subdomain)
root_records = await piglet.dns.get_by_name_type(
"example.com",
record_type="A"
)
Create Records¶
from oinker import AsyncPiglet, ARecord, MXRecord, TXTRecord
async with AsyncPiglet() as piglet:
# A record for www subdomain
record_id = await piglet.dns.create(
"example.com",
ARecord(content="1.2.3.4", name="www")
)
print(f"Created record: {record_id}")
# MX record with priority
await piglet.dns.create(
"example.com",
MXRecord(content="mail.example.com", priority=10)
)
# TXT record for SPF
await piglet.dns.create(
"example.com",
TXTRecord(content="v=spf1 include:_spf.example.com ~all")
)
Edit Records¶
from oinker import ARecord
async with AsyncPiglet() as piglet:
# Edit by record ID
await piglet.dns.edit(
"example.com",
record_id="123456",
record=ARecord(content="5.6.7.8", name="www")
)
# Edit all matching records by name and type
await piglet.dns.edit_by_name_type(
"example.com",
record_type="A",
subdomain="www",
content="5.6.7.8"
)
Delete Records¶
async with AsyncPiglet() as piglet:
# Delete by record ID
await piglet.dns.delete("example.com", record_id="123456")
# Delete all matching records by name and type
await piglet.dns.delete_by_name_type(
"example.com",
record_type="A",
subdomain="www"
)
Operations¶
AsyncDNSAPI¶
oinker.dns.AsyncDNSAPI
¶
Async DNS operations for the Porkbun API.
Accessed via piglet.dns.* methods.
Initialize DNS API.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
http
|
HttpClient
|
The HTTP client for making requests. |
required |
Source code in src/oinker/dns/_api.py
list
async
¶
List all DNS records for a domain.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
domain
|
str
|
The domain name (e.g., "example.com"). |
required |
Returns:
| Type | Description |
|---|---|
list[DNSRecordResponse]
|
List of DNS records. |
Raises:
| Type | Description |
|---|---|
AuthenticationError
|
If credentials are invalid. |
NotFoundError
|
If domain is not found. |
APIError
|
If the request fails. |
Source code in src/oinker/dns/_api.py
get
async
¶
Get a specific DNS record by ID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
domain
|
str
|
The domain name. |
required |
record_id
|
str
|
The record ID. |
required |
Returns:
| Type | Description |
|---|---|
DNSRecordResponse | None
|
The DNS record, or None if not found. |
Raises:
| Type | Description |
|---|---|
AuthenticationError
|
If credentials are invalid. |
APIError
|
If the request fails. |
Source code in src/oinker/dns/_api.py
get_by_name_type
async
¶
get_by_name_type(
domain: str,
record_type: str,
subdomain: str | None = None,
) -> builtins.list[DNSRecordResponse]
Get DNS records by subdomain and type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
domain
|
str
|
The domain name. |
required |
record_type
|
str
|
The record type (A, AAAA, MX, etc.). |
required |
subdomain
|
str | None
|
The subdomain (None for root). |
None
|
Returns:
| Type | Description |
|---|---|
list[DNSRecordResponse]
|
List of matching DNS records. |
Raises:
| Type | Description |
|---|---|
AuthenticationError
|
If credentials are invalid. |
NotFoundError
|
If no records match. |
APIError
|
If the request fails. |
Source code in src/oinker/dns/_api.py
create
async
¶
Create a new DNS record.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
domain
|
str
|
The domain name. |
required |
record
|
DNSRecord
|
The DNS record to create. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The ID of the created record. |
Raises:
| Type | Description |
|---|---|
AuthenticationError
|
If credentials are invalid. |
ValidationError
|
If record data is invalid. |
APIError
|
If the request fails. |
Source code in src/oinker/dns/_api.py
edit
async
¶
Edit an existing DNS record by ID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
domain
|
str
|
The domain name. |
required |
record_id
|
str
|
The record ID to edit. |
required |
record
|
DNSRecord
|
The new record data. |
required |
Raises:
| Type | Description |
|---|---|
AuthenticationError
|
If credentials are invalid. |
NotFoundError
|
If record is not found. |
ValidationError
|
If record data is invalid. |
APIError
|
If the request fails. |
Source code in src/oinker/dns/_api.py
edit_by_name_type
async
¶
edit_by_name_type(
domain: str,
record_type: str,
subdomain: str | None = None,
*,
content: str,
ttl: int | None = None,
priority: int | None = None,
notes: str | None = None,
) -> None
Edit all records matching subdomain and type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
domain
|
str
|
The domain name. |
required |
record_type
|
str
|
The record type (A, AAAA, MX, etc.). |
required |
subdomain
|
str | None
|
The subdomain (None for root). |
None
|
content
|
str
|
The new content value. |
required |
ttl
|
int | None
|
Optional new TTL. |
None
|
priority
|
int | None
|
Optional new priority. |
None
|
notes
|
str | None
|
Optional new notes (empty string clears, None leaves unchanged). |
None
|
Raises:
| Type | Description |
|---|---|
AuthenticationError
|
If credentials are invalid. |
NotFoundError
|
If no records match. |
APIError
|
If the request fails. |
Source code in src/oinker/dns/_api.py
delete
async
¶
Delete a DNS record by ID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
domain
|
str
|
The domain name. |
required |
record_id
|
str
|
The record ID to delete. |
required |
Raises:
| Type | Description |
|---|---|
AuthenticationError
|
If credentials are invalid. |
NotFoundError
|
If record is not found. |
APIError
|
If the request fails. |
Source code in src/oinker/dns/_api.py
delete_by_name_type
async
¶
Delete all records matching subdomain and type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
domain
|
str
|
The domain name. |
required |
record_type
|
str
|
The record type (A, AAAA, MX, etc.). |
required |
subdomain
|
str | None
|
The subdomain (None for root). |
None
|
Raises:
| Type | Description |
|---|---|
AuthenticationError
|
If credentials are invalid. |
NotFoundError
|
If no records match. |
APIError
|
If the request fails. |
Source code in src/oinker/dns/_api.py
SyncDNSAPI¶
oinker.dns.SyncDNSAPI
¶
Bases: SyncAPIBase['AsyncDNSAPI']
Synchronous DNS operations for the Porkbun API.
Accessed via piglet.dns.* methods.
Source code in src/oinker/_sync_base.py
list
¶
get
¶
get_by_name_type
¶
get_by_name_type(
domain: str,
record_type: str,
subdomain: str | None = None,
) -> builtins.list[DNSRecordResponse]
See :meth:AsyncDNSAPI.get_by_name_type.
Source code in src/oinker/dns/_sync.py
create
¶
edit
¶
edit_by_name_type
¶
edit_by_name_type(
domain: str,
record_type: str,
subdomain: str | None = None,
*,
content: str,
ttl: int | None = None,
priority: int | None = None,
notes: str | None = None,
) -> None
See :meth:AsyncDNSAPI.edit_by_name_type.
Source code in src/oinker/dns/_sync.py
delete
¶
delete_by_name_type
¶
See :meth:AsyncDNSAPI.delete_by_name_type.
Record Types¶
All record types validate their content on construction.
ARecord¶
oinker.ARecord
dataclass
¶
A record pointing to an IPv4 address.
Attributes:
| Name | Type | Description |
|---|---|---|
content |
str
|
IPv4 address (validated on init). |
name |
str | None
|
Subdomain (None = root domain, "*" = wildcard). |
ttl |
int
|
Time to live in seconds (min 600). |
notes |
str | None
|
Optional notes for the record. |
__post_init__
¶
Validate the record content.
AAAARecord¶
oinker.AAAARecord
dataclass
¶
AAAA record pointing to an IPv6 address.
Attributes:
| Name | Type | Description |
|---|---|---|
content |
str
|
IPv6 address (validated on init). |
name |
str | None
|
Subdomain (None = root domain, "*" = wildcard). |
ttl |
int
|
Time to live in seconds (min 600). |
notes |
str | None
|
Optional notes for the record. |
__post_init__
¶
MXRecord¶
oinker.MXRecord
dataclass
¶
MXRecord(
content: str,
priority: int = 10,
name: str | None = None,
ttl: int = 600,
notes: str | None = None,
)
MX record for mail servers.
Attributes:
| Name | Type | Description |
|---|---|---|
content |
str
|
Mail server hostname. |
priority |
int
|
Mail priority (lower = higher priority). |
name |
str | None
|
Subdomain (None = root domain). |
ttl |
int
|
Time to live in seconds (min 600). |
notes |
str | None
|
Optional notes for the record. |
__post_init__
¶
TXTRecord¶
oinker.TXTRecord
dataclass
¶
TXT record for arbitrary text data.
Attributes:
| Name | Type | Description |
|---|---|---|
content |
str
|
Text content. |
name |
str | None
|
Subdomain (None = root domain). |
ttl |
int
|
Time to live in seconds (min 600). |
notes |
str | None
|
Optional notes for the record. |
CNAMERecord¶
oinker.CNAMERecord
dataclass
¶
CNAME record pointing to another hostname.
Attributes:
| Name | Type | Description |
|---|---|---|
content |
str
|
Target hostname. |
name |
str | None
|
Subdomain (None allowed, but may be rejected by API for root CNAMEs). |
ttl |
int
|
Time to live in seconds (min 600). |
notes |
str | None
|
Optional notes for the record. |
ALIASRecord¶
oinker.ALIASRecord
dataclass
¶
ALIAS record (ANAME) for root domain CNAME-like behavior.
Attributes:
| Name | Type | Description |
|---|---|---|
content |
str
|
Target hostname. |
name |
str | None
|
Subdomain (None = root domain). |
ttl |
int
|
Time to live in seconds (min 600). |
notes |
str | None
|
Optional notes for the record. |
NSRecord¶
oinker.NSRecord
dataclass
¶
NS record delegating to a name server.
Attributes:
| Name | Type | Description |
|---|---|---|
content |
str
|
Nameserver hostname. |
name |
str | None
|
Subdomain (None = root domain). |
ttl |
int
|
Time to live in seconds (min 600). |
notes |
str | None
|
Optional notes for the record. |
SRVRecord¶
oinker.SRVRecord
dataclass
¶
SRVRecord(
content: str,
priority: int = 10,
name: str | None = None,
ttl: int = 600,
notes: str | None = None,
)
SRV record for service discovery.
Content format: "weight port target" (e.g., "5 5060 sipserver.example.com")
Attributes:
| Name | Type | Description |
|---|---|---|
content |
str
|
SRV data in "weight port target" format. |
priority |
int
|
Service priority (lower = higher priority). |
name |
str | None
|
Service name (e.g., "_sip._tcp"). |
ttl |
int
|
Time to live in seconds (min 600). |
notes |
str | None
|
Optional notes for the record. |
TLSARecord¶
oinker.TLSARecord
dataclass
¶
TLSA record for DANE TLS authentication.
Content format: "usage selector matching_type certificate_data"
Attributes:
| Name | Type | Description |
|---|---|---|
content |
str
|
TLSA data. |
name |
str | None
|
Port and protocol prefix (e.g., "_443._tcp"). |
ttl |
int
|
Time to live in seconds (min 600). |
notes |
str | None
|
Optional notes for the record. |
CAARecord¶
oinker.CAARecord
dataclass
¶
CAA record for certificate authority authorization.
Content format: 'flags tag "value"' (e.g., '0 issue "letsencrypt.org"')
Attributes:
| Name | Type | Description |
|---|---|---|
content |
str
|
CAA data. |
name |
str | None
|
Subdomain (None = root domain). |
ttl |
int
|
Time to live in seconds (min 600). |
notes |
str | None
|
Optional notes for the record. |
HTTPSRecord¶
oinker.HTTPSRecord
dataclass
¶
HTTPSRecord(
content: str,
priority: int = 1,
name: str | None = None,
ttl: int = 600,
notes: str | None = None,
)
HTTPS record for service binding.
Attributes:
| Name | Type | Description |
|---|---|---|
content |
str
|
HTTPS SVCB data. |
priority |
int
|
Priority (0 = alias mode). |
name |
str | None
|
Subdomain (None = root domain). |
ttl |
int
|
Time to live in seconds (min 600). |
notes |
str | None
|
Optional notes for the record. |
SVCBRecord¶
oinker.SVCBRecord
dataclass
¶
SVCBRecord(
content: str,
priority: int = 1,
name: str | None = None,
ttl: int = 600,
notes: str | None = None,
)
SVCB record for general service binding.
Attributes:
| Name | Type | Description |
|---|---|---|
content |
str
|
SVCB data. |
priority |
int
|
Priority (0 = alias mode). |
name |
str | None
|
Subdomain (None = root domain). |
ttl |
int
|
Time to live in seconds (min 600). |
notes |
str | None
|
Optional notes for the record. |
SSHFPRecord¶
oinker.SSHFPRecord
dataclass
¶
SSHFP record for SSH fingerprint verification.
Content format: "algorithm fingerprint_type fingerprint"
Attributes:
| Name | Type | Description |
|---|---|---|
content |
str
|
SSHFP data. |
name |
str | None
|
Subdomain (None = root domain). |
ttl |
int
|
Time to live in seconds (min 600). |
notes |
str | None
|
Optional notes for the record. |
Response Types¶
DNSRecordResponse¶
oinker.DNSRecordResponse
dataclass
¶
DNSRecordResponse(
id: str,
name: str,
record_type: str,
content: str,
ttl: int,
priority: int = 0,
notes: str = "",
)
A DNS record as returned from the API.
Attributes:
| Name | Type | Description |
|---|---|---|
id |
str
|
Unique record identifier. |
name |
str
|
Full domain name (e.g., "www.example.com"). |
record_type |
str
|
DNS record type (A, AAAA, etc.). |
content |
str
|
Record content/answer. |
ttl |
int
|
Time to live in seconds. |
priority |
int
|
Record priority (for MX, SRV, etc.). |
notes |
str
|
Optional notes. |
from_api_response
classmethod
¶
Create a DNSRecordResponse from API response data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
dict[str, str]
|
Dictionary from Porkbun API. |
required |
Returns:
| Type | Description |
|---|---|
DNSRecordResponse
|
Parsed DNSRecordResponse. |