A Python-based command-line tool for managing Namecheap DNS records easily. It supports:
- Listing all DNS records for a given domain (
listmode) - Adding/updating a single DNS record while preserving others (
setmode) - Deduplication: if a record with the same type and host exists, it will be replaced; if value is the same, it will be skipped
Ideal for CI/CD automation, local DNS management, and quick CLI modifications.
- Features
- How It Works
- Requirements
- Configuration
- Quick Start
- Advanced Usage
- FAQ
- References
- Contributing
- License
| Feature | Description |
|---|---|
| List Records | python namecheap_dns.py list prints records as type,host,value |
| Add/Update Record | python namecheap_dns.py set <TYPE> <HOST> <VALUE> |
| Deduplication | Same TYPE + HOST → overwrite; identical record → skip |
- Fetch records using
namecheap.domains.dns.getHosts - Merge with the new one, replacing duplicates
- Submit all records with
namecheap.domains.dns.setHosts
Note:
setHostsreplaces the entire DNS table. Always fetch-merge-set.
- Python ≥ 3.8
- import requests
- import xml.etree.ElementTree
- import sys
Edit the top of namecheap_dns.py:
API_USER = "your_api_user"
API_KEY = "your_api_key"
USERNAME = "your_username"
CLIENT_IP = "your_whitelisted_ip"
DOMAIN_SLD = "example"
DOMAIN_TLD = "com"Before using the API, your current public IP must be whitelisted:
- Log in to Namecheap Dashboard
- Go to API Access
- Add your current public IP to the whitelist (multiple entries allowed)
- Wait 1-5 minutes to take effect
Otherwise, you'll receive the error: IP address is not whitelisted
python namecheap_easy.py listExample output:
A,@,93.184.216.34
CNAME,www,example.com
python namecheap_easy.py set A blog 1.2.3.4- If
A blogexists with different value → overwrite - If identical record exists → skip
Q1: Why am I getting
IP address is not whitelisted?A1: Go to Namecheap → Profile → API Access and add your public IP.
Q2: Can I add more than one record?
A2: Yes. Just append more entries to the
filtered_recordslist.
Q3: Can this be used with sub-accounts?
A3: Yes, as long as they have proper API permissions.
- Official Namecheap API Documentation:
Welcomed contributions:
- Features (batch import, deletion, async)
- Bug fixes
- Docs improvements
MIT License. See LICENSE.
Disclaimer: This project is not affiliated with Namecheap. Use at your own risk and store your API credentials securely.