Skip to main content

Command-line tool for managing Porkbun domains and DNS records

Project description

porkbun-cli

Python 3.8+ PyPI License: MIT

A command-line tool for managing domains and DNS records through the Porkbun API.

$ porkbun dns list example.com

ID          Type  Name               Content         Prio  TTL
----------  ----  -----------------  --------------  ----  -----
123456789   A     example.com        203.0.113.1           600
123456790   MX    example.com        mail.example.com  10  3600
123456791   TXT   example.com        v=spf1 ...            3600

Install

pip install porkbun

# With interactive menu support
pip install porkbun[interactive]

Setup

Get your API keys from porkbun.com/account/api. You need to enable API access per-domain in your Porkbun account settings.

Then run:

porkbun configure

This prompts for your API key and secret, then saves them to ~/.config/porkbun-cli/config.json with 600 permissions.

To verify the connection works:

porkbun ping
# Success! Your IP: 203.0.113.42

Commands

Domains

# List all domains in your account
porkbun domain list

# Check availability and pricing for a domain
porkbun domain search coolname.com

# Register a domain (prompts for confirmation before charging)
porkbun domain buy coolname.com

# View nameservers
porkbun domain ns example.com

# Set custom nameservers
porkbun domain ns-set example.com ns1.host.com ns2.host.com

# Download SSL certificate bundle
porkbun domain ssl example.com --output ./certs/example
# Writes example.crt, example.key, example.ca

DNS Records

# List all records
porkbun dns list example.com

# Filter by type
porkbun dns list example.com --type TXT

# Create records
porkbun dns create example.com A 203.0.113.1 --name www
porkbun dns create example.com MX mail.example.com --prio 10
porkbun dns create example.com TXT "v=spf1 include:example.com ~all"
porkbun dns create example.com CNAME target.example.com --name blog

# Edit a record by its ID
porkbun dns edit example.com 123456789 A 203.0.113.2 --name www

# Upsert — creates the record if it doesn't exist, updates it if it does
porkbun dns upsert example.com A 203.0.113.1 --name www

# Delete by ID
porkbun dns delete example.com 123456789

Supported record types: A, AAAA, CNAME, ALIAS, MX, TXT, NS, SRV, TLSA, CAA, HTTPS, SVCB, SSHFP

URL Forwarding

# List URL forwards
porkbun url list example.com

# Set a redirect (302 by default)
porkbun url set example.com https://destination.com

# Set a permanent 301 redirect from a subdomain
porkbun url set example.com https://destination.com --subdomain blog --type 301

# Wildcard redirect with path passthrough
porkbun url set example.com https://destination.com --wildcard --path

# Delete a forward
porkbun url delete example.com 987654321

Bulk Export / Import

Good for backups or migrating DNS between domains.

# Export all DNS records to JSON
porkbun bulk export example.com -o records.json

# Export as CSV
porkbun bulk export example.com --format csv -o records.csv

# Print to stdout (pipe-friendly)
porkbun bulk export example.com

# Preview what an import would do without changing anything
porkbun bulk import records.json --dry-run

# Import to original domain (reads domain from JSON file)
porkbun bulk import records.json

# Import to a different domain
porkbun bulk import records.json --domain newdomain.com

The JSON format supports an optional action field per record: create (default), upsert, or delete.

Interactive Mode

Install with [interactive] to get a menu-driven interface instead of remembering all the flags:

porkbun interactive
# or shorthand:
porkbun i

Fetches your domain list on startup so you can pick from a menu — handy when you manage several domains.

Config File

Credentials are stored at ~/.config/porkbun-cli/config.json:

{
    "apikey": "pk1_...",
    "secretapikey": "sk1_..."
}

The file is created with 600 permissions by porkbun configure. Do not commit it.

You can also pass keys directly via environment or by instantiating PorkbunAPI programmatically — see the api.py module if you want to use the client in your own scripts.

Requirements

  • Python 3.8+
  • requests
  • tabulate
  • questionary (only for porkbun interactive, installed via pip install porkbun-cli[interactive])

License

MIT — see LICENSE.

Author

Luke Steuber · GitHub · Bluesky

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

porkbun-1.0.0.tar.gz (13.7 kB view details)

Uploaded Source

Built Distribution

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

porkbun-1.0.0-py3-none-any.whl (15.7 kB view details)

Uploaded Python 3

File details

Details for the file porkbun-1.0.0.tar.gz.

File metadata

  • Download URL: porkbun-1.0.0.tar.gz
  • Upload date:
  • Size: 13.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.12

File hashes

Hashes for porkbun-1.0.0.tar.gz
Algorithm Hash digest
SHA256 9da1bb00864f5a89589591ecd745c02fdf29b55e74786cb58daf8147548afea8
MD5 17980a59d661b7e97ae816e81c31fb12
BLAKE2b-256 298ae920bd0e2257089ef00c9cd90d4c71652af169fa21af6b3db8a089615a1f

See more details on using hashes here.

File details

Details for the file porkbun-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: porkbun-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 15.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.12

File hashes

Hashes for porkbun-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 73f2c73bde10e8ef77d5c6d1bd6c6f63d2a8c467bea2166847b81c6d26661895
MD5 b7f3f33457f470cd0b2853e71d99a583
BLAKE2b-256 72b1b9dee27f0c3528d744c929423b97e892d2bb1c5c5776518ebd870e32974e

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