A friendly Python SDK for Namecheap API
Project description
Namecheap Python SDK
A modern, friendly Python SDK for the Namecheap API with comprehensive CLI and TUI tools.
๐ Features
- Modern Python SDK with full type hints and Pydantic models
- CLI Tool for managing domains and DNS from the terminal
- TUI Application for visual DNS record management
- Smart DNS Builder with fluent interface for record management
- Auto-configuration from environment variables
- Helpful error messages with troubleshooting guidance
- Comprehensive logging with beautiful colored output
- Sandbox support for safe testing
๐ฏ Quick Start
Requires Python 3.12 or higher
namecheap-python: Core Python SDK Library
# Add as a dependency to your project
uv add namecheap-python
from namecheap import Namecheap
# Initialize (auto-loads from environment)
nc = Namecheap()
# Check domain availability
domains = nc.domains.check("example.com", "coolstartup.io")
for domain in domains:
if domain.available:
print(f"โ
{domain.domain} is available!")
# List your domains
my_domains = nc.domains.list()
for domain in my_domains:
print(f"{domain.name} expires on {domain.expires}")
# Manage DNS with the builder
nc.dns.set("example.com",
nc.dns.builder()
.a("@", "192.0.2.1")
.a("www", "192.0.2.1")
.mx("@", "mail.example.com", priority=10)
.txt("@", "v=spf1 include:_spf.google.com ~all")
)
namecheap-cli: CLI tool
It was meant as a proof of concept to showcase namecheap-python, but it is a tool that I use
# List domains with beautiful table output
# Run it without install with:
uvx --from 'namecheap-python[cli]' namecheap-cli domain list
# Or install it permanently with:
uv tool install --python 3.12 'namecheap-python[cli]'
# Then run
namecheap-cli domain list
Domains (4 total)
โโโโโโโโโโโโโโโโโโโโโณโโโโโโโโโณโโโโโโโโโโโโโณโโโโโโโโโโโโโณโโโโโโโโโ
โ Domain โ Status โ Expires โ Auto-Renew โ Locked โ
โกโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฉ
โ example.com โ Active โ 2025-10-21 โ โ โ โ
โ coolsite.io โ Active โ 2026-05-25 โ โ โ โ
โ myproject.dev โ Active โ 2026-05-30 โ โ โ โ
โ awesome.site โ Active โ 2026-03-20 โ โ โ โ
โโโโโโโโโโโโโโโโโโโโโดโโโโโโโโโดโโโโโโโโโโโโโดโโโโโโโโโโโโโดโโโโโโโโโ
Configure it before first use:
# Interactive setup
namecheap-cli config init
# Creates config file at:
# - Linux/macOS: $XDG_CONFIG_HOME/namecheap/config.yaml (or ~/.config/namecheap/config.yaml)
# - Windows: %APPDATA%\namecheap\config.yaml
Check domain availability and pricing:
# Check domain availability
โฏ namecheap-cli domain check myawesome.com coolstartup.io
Domain Availability
โโโโโโโโโโโโโโโโโโณโโโโโโโโโโโโโโโณโโโโโโโโโโโโโโโโโโโ
โ Domain โ Available โ Price (USD/year) โ
โกโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฉ
โ myawesome.com โ โ Taken โ - โ
โ coolstartup.io โ โ
Available โ $34.98 โ
โโโโโโโโโโโโโโโโโโดโโโโโโโโโโโโโโโดโโโโโโโโโโโโโโโโโโโ
๐ก Suggestions for taken domains:
โข myawesome.com โ myawesome.net, myawesome.io, getmyawesome.com
Manage DNS records:
In this example I'll set up GitHub Pages for my domain tdo.garden
# First, check current DNS records (before setup)
namecheap-cli dns list tdo.garden
# Initial state (Namecheap default parking page):
DNS Records for tdo.garden (2 total)
โโโโโโโโโโโโณโโโโโโโโโโโโโโโโโโโโโโโณโโโโโโโโโโโโโโโโโโโโโโโโโโโโโณโโโโโโโโโโโณโโโโโโโโโโโ
โ Type โ Name โ Value โ TTL โ Priority โ
โกโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฉ
โ CNAME โ www โ parkingpage.namecheap.com. โ 1800 โ 10 โ
โ URL โ @ โ http://www.tdo.garden/ โ 1800 โ 10 โ
โโโโโโโโโโโโดโโโโโโโโโโโโโโโโโโโโโโโดโโโโโโโโโโโโโโโโโโโโโโโโโโโโโดโโโโโโโโโโโดโโโโโโโโโโโ
# Add GitHub Pages A records for apex domain
โฏ namecheap-cli dns add tdo.garden A @ 185.199.108.153
Adding A record to tdo.garden...
โ
Added A record successfully!
โฏ namecheap-cli dns add tdo.garden A @ 185.199.109.153
Adding A record to tdo.garden...
โ
Added A record successfully!
โฏ namecheap-cli dns add tdo.garden A @ 185.199.110.153
Adding A record to tdo.garden...
โ
Added A record successfully!
โฏ namecheap-cli dns add tdo.garden A @ 185.199.111.153
Adding A record to tdo.garden...
โ
Added A record successfully!
# Add CNAME for www subdomain
โฏ namecheap-cli dns add tdo.garden CNAME www adriangalilea.github.io
Adding CNAME record to tdo.garden...
โ
Added CNAME record successfully!
# Verify the setup
โฏ namecheap-cli dns list tdo.garden
# Final state with GitHub Pages + old records still present that you may want to remove:
```bash
DNS Records for tdo.garden (7 total)
โโโโโโโโโโโโณโโโโโโโโโโโโโโโโโโโโโโโณโโโโโโโโโโโโโโโโโโโโโโโโโโโโโณโโโโโโโโโโโณโโโโโโโโโโโ
โ Type โ Name โ Value โ TTL โ Priority โ
โกโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฉ
โ A โ @ โ 185.199.108.153 โ 1800 โ 10 โ
โ A โ @ โ 185.199.109.153 โ 1800 โ 10 โ
โ A โ @ โ 185.199.110.153 โ 1800 โ 10 โ
โ A โ @ โ 185.199.111.153 โ 1800 โ 10 โ
โ CNAME โ www โ parkingpage.namecheap.com. โ 1800 โ 10 โ
โ CNAME โ www โ adriangalilea.github.io. โ 1800 โ 10 โ
โ URL โ @ โ http://www.tdo.garden/ โ 1800 โ 10 โ
โโโโโโโโโโโโดโโโโโโโโโโโโโโโโโโโโโโโดโโโโโโโโโโโโโโโโโโโโโโโโโโโโโดโโโโโโโโโโโดโโโโโโโโโโโ
Check account balance:
โฏ namecheap-cli account balance
Account Balance
โโโโโโโโโโโโโโโโโโโโโโโณโโโโโโโโโโโโ
โ Field โ Amount โ
โกโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฉ
โ Available Balance โ 0.00 USD โ
โ Account Balance โ 0.00 USD โ
โ Earned Amount โ 0.00 USD โ
โ Withdrawable โ 0.00 USD โ
โ Auto-Renew Required โ 20.16 USD โ
โโโโโโโโโโโโโโโโโโโโโโโดโโโโโโโโโโโโ
Get detailed domain info:
โฏ namecheap-cli domain info self.fm
Domain Information: self.fm
Status: Ok
Owner: adriangalilea
Created: 07/15/2023
Expires: 07/15/2026
Premium: No
WHOIS Guard: โ Enabled
DNS Provider: CUSTOM
You can also export DNS records:
namecheap-cli dns export example.com --format yaml
namecheap-dns-tui: TUI for DNS management
# Launch interactive DNS manager
namecheap-dns-tui
Install both the CLI and TUI
uv tool install --python 3.12 'namecheap-python[all]'
๐ Documentation
- Examples Overview - Quick examples for all tools
- CLI Documentation - Complete CLI reference
- TUI Documentation - TUI features and usage
- SDK Quickstart - Python code examples
โ๏ธ Configuration
Environment Variables
Create a .env file or set environment variables:
# Required
NAMECHEAP_API_KEY=your-api-key
NAMECHEAP_USERNAME=your-username
# Optional
NAMECHEAP_API_USER=api-username # defaults to USERNAME
NAMECHEAP_CLIENT_IP=auto # auto-detected if not set
NAMECHEAP_SANDBOX=false # use production API
Python Configuration
from namecheap import Namecheap
nc = Namecheap(
api_key="your-api-key",
username="your-username",
api_user="api-username", # Optional
client_ip="1.2.3.4", # Optional, auto-detected
sandbox=False # Production mode
)
๐ง Advanced SDK Usage
DNS Builder Pattern
The DNS builder provides a fluent interface for managing records:
# Build complex DNS configurations
nc.dns.set("example.com",
nc.dns.builder()
# A records
.a("@", "192.0.2.1")
.a("www", "192.0.2.1")
.a("blog", "192.0.2.2")
# AAAA records
.aaaa("@", "2001:db8::1")
.aaaa("www", "2001:db8::1")
# MX records
.mx("@", "mail.example.com", priority=10)
.mx("@", "mail2.example.com", priority=20)
# TXT records
.txt("@", "v=spf1 include:_spf.google.com ~all")
.txt("_dmarc", "v=DMARC1; p=none;")
# CNAME records
.cname("blog", "myblog.wordpress.com")
.cname("shop", "myshop.shopify.com")
# URL redirects
.url("old", "https://new-site.com", redirect_type="301")
)
Note on TTL: The default TTL is 1799 seconds, which displays as "Automatic" in the Namecheap web interface. This is an undocumented Namecheap API behavior. You can specify custom TTL values (60-86400 seconds) in any DNS method.
Nameserver Management
# Check current nameservers
ns = nc.dns.get_nameservers("example.com")
print(ns.nameservers) # ['dns1.registrar-servers.com', 'dns2.registrar-servers.com']
print(ns.is_default) # True
# Switch to custom nameservers (e.g., Cloudflare, Route 53)
nc.dns.set_custom_nameservers("example.com", [
"ns1.cloudflare.com",
"ns2.cloudflare.com",
])
# Reset back to Namecheap BasicDNS
nc.dns.set_default_nameservers("example.com")
Domain Info
info = nc.domains.get_info("example.com")
print(info.status) # 'Ok'
print(info.whoisguard_enabled) # True
print(info.dns_provider) # 'CUSTOM'
print(info.created) # '07/15/2023'
print(info.expires) # '07/15/2026'
Account Balance
bal = nc.users.get_balances()
print(f"{bal.available_balance} {bal.currency}") # '4932.96 USD'
print(bal.funds_required_for_auto_renew) # Decimal('20.16')
Pricing
# Get registration pricing for a specific TLD
pricing = nc.users.get_pricing("DOMAIN", action="REGISTER", product_name="com")
for p in pricing["REGISTER"]["com"]:
print(f"{p.duration} year: ${p.your_price} (regular: ${p.regular_price})")
# Get all domain pricing (large response โ cache it)
all_pricing = nc.users.get_pricing("DOMAIN")
Email Forwarding
# Read
rules = nc.dns.get_email_forwarding("example.com")
for r in rules:
print(f"{r.mailbox} -> {r.forward_to}")
# Write (replaces all existing rules)
nc.dns.set_email_forwarding("example.com", [
EmailForward(mailbox="info", forward_to="me@gmail.com"),
EmailForward(mailbox="support", forward_to="help@gmail.com"),
])
Domain Contacts
contacts = nc.domains.get_contacts("example.com")
print(f"{contacts.registrant.first_name} {contacts.registrant.last_name}")
print(contacts.registrant.email)
TLD List
tlds = nc.domains.get_tld_list()
print(f"{len(tlds)} TLDs supported")
# Filter to API-registerable TLDs
registerable = [t for t in tlds if t.is_api_registerable]
for t in registerable[:5]:
print(f".{t.name} ({t.type}) โ {t.min_register_years}-{t.max_register_years} years")
Domain Privacy (WhoisGuard)
# List all WhoisGuard subscriptions
entries = nc.whoisguard.get_list()
for e in entries:
print(f"{e.domain} (ID={e.id}) status={e.status}")
# Enable privacy (resolves WhoisGuard ID from domain name automatically)
nc.whoisguard.enable("example.com", "me@gmail.com")
# Disable privacy
nc.whoisguard.disable("example.com")
# Renew privacy
result = nc.whoisguard.renew("example.com", years=1)
print(f"Charged: {result['charged_amount']}")
# Rotate the masked forwarding email
result = nc.whoisguard.change_email("example.com")
print(f"New: {result['new_email']}")
Domain Management
# Check multiple domains with pricing
results = nc.domains.check(
"example.com",
"coolstartup.io",
"myproject.dev",
include_pricing=True
)
for domain in results:
if domain.available:
print(f"โ
{domain.domain} - ${domain.price}/year")
else:
print(f"โ {domain.domain} is taken")
# List domains with filters
domains = nc.domains.list()
expiring_soon = [d for d in domains if (d.expires - datetime.now()).days < 30]
# Register a domain
from namecheap import Contact
contact = Contact(
first_name="John",
last_name="Doe",
address1="123 Main St",
city="New York",
state_province="NY",
postal_code="10001",
country="US",
phone="+1.2125551234",
email="john@example.com"
)
result = nc.domains.register(
"mynewdomain.com",
years=2,
contact=contact,
whois_protection=True
)
Error Handling
from namecheap import NamecheapError
try:
nc.domains.check("example.com")
except NamecheapError as e:
print(f"Error: {e.message}")
if e.help:
print(f"๐ก Tip: {e.help}")
โ ๏ธ Namecheap API Quirks
This section documents undocumented or unusual Namecheap API behaviors we've discovered:
No WHOIS lookups or Marketplace data
The Namecheap API only operates on domains in your account. There is no API for:
- WHOIS lookups on arbitrary domains
- Checking if a domain is listed on Namecheap Marketplace
- Aftermarket pricing or availability
domains.check() tells you if a domain is unregistered, not if it's for sale by its owner.
TTL "Automatic" = 1799 seconds
The Namecheap web interface displays TTL as "Automatic" when the value is exactly 1799 seconds, but shows "30 min" when it's 1800 seconds. This behavior is completely undocumented in their official API documentation.
Their API docs state TTL defaults to 1800 when omitted, but the UI treats 1799 specially. This SDK defaults to 1799 to match the "Automatic" behavior users see in the web interface.
# Both are valid, but display differently in Namecheap UI:
nc.dns.builder().a("www", "192.0.2.1", ttl=1799) # Shows as "Automatic"
nc.dns.builder().a("www", "192.0.2.1", ttl=1800) # Shows as "30 min"
๐ API Coverage
| API | Status | Methods |
|---|---|---|
namecheap.domains.* |
โ Done | check, list, getInfo, getContacts, getTldList, register, renew, setContacts, lock/unlock |
namecheap.domains.dns.* |
โ Done | getHosts, setHosts (builder pattern), add, delete, export, getList, setCustom, setDefault, getEmailForwarding, setEmailForwarding |
namecheap.whoisguard.* |
โ Done | getList, enable, disable, renew, changeEmailAddress |
namecheap.users.* |
โ ๏ธ Partial | getBalances, getPricing. Remaining methods are account management (changePassword, update, create, login, resetPassword) โ only useful if building a reseller platform |
namecheap.users.address.* |
๐ง Planned | Saved address book for domains.register() โ store contacts once, reuse by ID instead of passing full contact info every time |
namecheap.ssl.* |
๐ง Planned | Full SSL certificate lifecycle โ purchase, activate with CSR, renew, revoke, reissue. Complex multi-step workflows with approval emails |
namecheap.domains.transfer.* |
๐ง Planned | Transfer domains into Namecheap programmatically โ initiate, track status, retry |
namecheap.domains.ns.* |
๐ง Planned | Glue records โ only needed if you run your own nameservers and need to register them with the registry |
namecheap.domains.* |
๐ง Planned | reactivate โ restore expired domains within the redemption grace period |
๐ ๏ธ Development
See CONTRIBUTING.md for setup and development guidelines.
๐ License
MIT License - see LICENSE file for details.
๐ค Contributing
Contributions are welcome! Please feel free to submit a Pull Request. See CONTRIBUTING.md for setup instructions and guidelines.
Contributors
- @huntertur โ Rich dependency fix
- @jeffmcadams โ Domain serialization round-trip
- @cosmin โ Nameserver management
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file namecheap_python-1.5.0.tar.gz.
File metadata
- Download URL: namecheap_python-1.5.0.tar.gz
- Upload date:
- Size: 783.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4b40853c8b294399eff84c64c279b3267c25c2ad1ac0ccf3ff29da44a8a211ff
|
|
| MD5 |
94980a9cc44de94850d62a87c972f115
|
|
| BLAKE2b-256 |
e58177c0169c5a59e2215068387eceff234a32855385c5db98c429c9bdac4ede
|
Provenance
The following attestation bundles were made for namecheap_python-1.5.0.tar.gz:
Publisher:
release.yml on adriangalilea/namecheap-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
namecheap_python-1.5.0.tar.gz -
Subject digest:
4b40853c8b294399eff84c64c279b3267c25c2ad1ac0ccf3ff29da44a8a211ff - Sigstore transparency entry: 908546935
- Sigstore integration time:
-
Permalink:
adriangalilea/namecheap-python@d5cb29226bde6d4257b424e2e21b82fbd9b49f45 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/adriangalilea
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@d5cb29226bde6d4257b424e2e21b82fbd9b49f45 -
Trigger Event:
push
-
Statement type:
File details
Details for the file namecheap_python-1.5.0-py3-none-any.whl.
File metadata
- Download URL: namecheap_python-1.5.0-py3-none-any.whl
- Upload date:
- Size: 762.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fefb5622e59fe9105238bdacfe8ba9fd83ae80741b3950dec6ab0b2398d7cbaf
|
|
| MD5 |
7405a54b6a4e202b7c451c2d765ac154
|
|
| BLAKE2b-256 |
286d7ae6a8f6c24fe96ee01589ce6f9cd192ea6f74eebfa5ba8663ecfb1f0391
|
Provenance
The following attestation bundles were made for namecheap_python-1.5.0-py3-none-any.whl:
Publisher:
release.yml on adriangalilea/namecheap-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
namecheap_python-1.5.0-py3-none-any.whl -
Subject digest:
fefb5622e59fe9105238bdacfe8ba9fd83ae80741b3950dec6ab0b2398d7cbaf - Sigstore transparency entry: 908546970
- Sigstore integration time:
-
Permalink:
adriangalilea/namecheap-python@d5cb29226bde6d4257b424e2e21b82fbd9b49f45 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/adriangalilea
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@d5cb29226bde6d4257b424e2e21b82fbd9b49f45 -
Trigger Event:
push
-
Statement type: