Top Related Projects
Infrastructure as code for DNS!
Tools for managing DNS across multiple providers
The official Go library for the Cloudflare API
PowerDNS Authoritative, PowerDNS Recursor, dnsdist
Quick Overview
Lexicon is a powerful and flexible Python library for manipulating DNS records across various DNS providers. It provides a unified interface to interact with different DNS services, allowing users to manage DNS records programmatically without worrying about provider-specific APIs.
Pros
- Supports a wide range of DNS providers (over 50)
- Consistent API across different providers
- Extensible architecture, allowing easy addition of new providers
- Well-documented and actively maintained
Cons
- Learning curve for users new to DNS management
- Some providers may have limited functionality compared to others
- Requires separate authentication for each provider
- May not support all advanced features of individual DNS providers
Code Examples
- Creating a DNS record:
from lexicon.client import Client
from lexicon.config import ConfigResolver
# Create a client for Cloudflare
client = Client(ConfigResolver().with_dict({
'provider_name': 'cloudflare',
'domain': 'example.com',
'auth_username': 'your_email@example.com',
'auth_token': 'your_api_token'
}))
# Create an A record
client.create_record('A', 'subdomain', '192.168.0.1')
- Listing DNS records:
# List all TXT records
records = client.list_records('TXT')
for record in records:
print(f"Name: {record['name']}, Content: {record['content']}")
- Updating a DNS record:
# Update the IP address of an existing A record
client.update_record('A', 'subdomain', '192.168.0.2')
- Deleting a DNS record:
# Delete a specific CNAME record
client.delete_record('CNAME', 'old-subdomain', 'example.com')
Getting Started
To get started with Lexicon, follow these steps:
-
Install Lexicon using pip:
pip install dns-lexicon
-
Create a configuration file (e.g.,
lexicon.yml
) with your provider details:cloudflare: auth_username: your_email@example.com auth_token: your_api_token
-
Use Lexicon in your Python script:
from lexicon.client import Client from lexicon.config import ConfigResolver client = Client(ConfigResolver().with_config_file('lexicon.yml')) client.provider_name = 'cloudflare' client.domain = 'example.com' # Now you can use the client to manage DNS records client.create_record('A', 'subdomain', '192.168.0.1')
With these steps, you'll be able to start managing DNS records across various providers using Lexicon.
Competitor Comparisons
Infrastructure as code for DNS!
Pros of dnscontrol
- More comprehensive DNS management solution, offering a full declarative language for DNS configuration
- Supports a wider range of DNS providers and features
- Provides advanced features like syntax checking and diff generation
Cons of dnscontrol
- Steeper learning curve due to its domain-specific language
- Requires more setup and configuration compared to Lexicon's simpler approach
- May be overkill for users with simpler DNS management needs
Code Comparison
Lexicon example:
from lexicon.client import Client
lexicon = Client(provider_name='cloudflare', domain='example.com')
lexicon.create_record('A', 'www', '1.2.3.4')
dnscontrol example:
var REG_NONE = NewRegistrar('none', 'NONE');
var DNS_CLOUDFLARE = NewDnsProvider('cloudflare', 'CLOUDFLARE');
D('example.com', REG_NONE, DnsProvider(DNS_CLOUDFLARE),
A('www', '1.2.3.4')
);
Both Lexicon and dnscontrol offer DNS management capabilities, but they cater to different use cases. Lexicon provides a simple, straightforward API for basic DNS operations across multiple providers, while dnscontrol offers a more powerful and flexible solution for complex DNS configurations and management tasks.
Tools for managing DNS across multiple providers
Pros of octoDNS
- More comprehensive DNS management solution, handling multiple providers and record types
- Supports advanced features like geo-routing and traffic management
- Offers a declarative YAML-based configuration for easier management of complex DNS setups
Cons of octoDNS
- Steeper learning curve due to its more complex architecture
- Less focused on individual provider API interactions compared to Lexicon
- May be overkill for simple DNS management tasks
Code Comparison
Lexicon example:
from lexicon.client import Client
Client(provider_name='cloudflare', domain='example.com').authenticate(api_key='KEY')
.create_record('A', 'www', '1.2.3.4')
octoDNS example:
providers:
config:
class: octodns.provider.yaml.YamlProvider
directory: ./config
cloudflare:
class: octodns_cloudflare.CloudflareProvider
token: env/CLOUDFLARE_TOKEN
zones:
example.com.:
sources:
- config
targets:
- cloudflare
Both projects aim to simplify DNS management, but octoDNS offers a more comprehensive solution for managing complex DNS setups across multiple providers, while Lexicon focuses on providing a unified API for interacting with various DNS providers individually.
The official Go library for the Cloudflare API
Pros of cloudflare-go
- Specifically designed for Cloudflare API interactions, offering comprehensive coverage of Cloudflare services
- Written in Go, providing strong typing and concurrency support
- Actively maintained by Cloudflare, ensuring up-to-date API compatibility
Cons of cloudflare-go
- Limited to Cloudflare services only, not suitable for multi-provider DNS management
- Requires more setup and configuration compared to Lexicon's simpler interface
- Steeper learning curve for users not familiar with Go or Cloudflare's API structure
Code Comparison
Lexicon (Python):
from lexicon.providers.cloudflare import Provider
provider = Provider({'auth_username': 'email', 'auth_token': 'api_key'})
provider.create_record('example.com', 'A', 'subdomain', '1.2.3.4')
cloudflare-go (Go):
import "github.com/cloudflare/cloudflare-go"
api, _ := cloudflare.New("api_key", "email")
zoneID, _ := api.ZoneIDByName("example.com")
api.CreateDNSRecord(zoneID, cloudflare.DNSRecord{Type: "A", Name: "subdomain", Content: "1.2.3.4"})
Lexicon offers a more straightforward interface for basic DNS operations across multiple providers, while cloudflare-go provides deeper integration with Cloudflare-specific features at the cost of increased complexity and provider lock-in.
PowerDNS Authoritative, PowerDNS Recursor, dnsdist
Pros of pdns
- Comprehensive DNS server solution with authoritative server, recursor, and more
- Highly scalable and performant, suitable for large-scale deployments
- Extensive documentation and active community support
Cons of pdns
- Steeper learning curve due to its complexity and feature-rich nature
- Requires more system resources compared to lightweight alternatives
- May be overkill for simple DNS management tasks
Code Comparison
pdns (C++):
#include "dnsrecords.hh"
#include "dnswriter.hh"
#include "dnspacket.hh"
DNSPacket p;
p.setQuestion(DNSPacket::Question(DNSName("example.com"), QType::A));
lexicon (Python):
from lexicon.client import Client
from lexicon.config import ConfigResolver
action = {
'action': 'create',
'domain': 'example.com',
'type': 'A',
'name': 'www',
'content': '127.0.0.1'
}
Summary
pdns is a full-featured DNS server solution, offering high performance and scalability for complex DNS infrastructures. It's well-suited for large-scale deployments but may be excessive for simpler use cases. lexicon, on the other hand, focuses on providing a unified interface for DNS providers, making it more accessible for basic DNS management tasks across multiple platforms.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
Manipulate DNS records on various DNS providers in a standardized/agnostic way.
[!IMPORTANT]
Starting with version 3.20.0, Lexicon has moved to a new repository:https://github.com/dns-lexicon/dns-lexicon
Please use this new repository for issues and merge requests.
[!NOTE]
Lexicon documentation (including development guide) is available here:
Top Related Projects
Infrastructure as code for DNS!
Tools for managing DNS across multiple providers
The official Go library for the Cloudflare API
PowerDNS Authoritative, PowerDNS Recursor, dnsdist
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot