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
============ |logo_named|
Manipulate DNS records on various DNS providers in a standardized/agnostic way.
|build_status| |coverage_status| |docker_pulls| |pypy_version| |pypy_python_support| |github_license|
.. |logo_named| image:: https://raw.githubusercontent.com/AnalogJ/lexicon/master/docs/images/logo_named.svg :alt: Lexicon .. |build_status| image:: https://img.shields.io/azure-devops/build/AnalogJ/8425f0f5-0178-4d8c-b1fd-11db7e11b6a7/1/master :target: https://dev.azure.com/AnalogJ/lexicon/_build/latest?definitionId=1&branchName=master .. |coverage_status| image:: https://img.shields.io/coverallsCoverage/github/AnalogJ/lexicon :target: https://coveralls.io/github/AnalogJ/lexicon?branch=master .. |docker_pulls| image:: https://img.shields.io/docker/pulls/analogj/lexicon :target: https://hub.docker.com/r/analogj/lexicon .. |pypy_version| image:: https://img.shields.io/pypi/v/dns-lexicon :target: https://pypi.python.org/pypi/dns-lexicon .. |pypy_python_support| image:: https://img.shields.io/pypi/pyversions/dns-lexicon :target: https://pypi.python.org/pypi/dns-lexicon .. |github_license| image:: https://img.shields.io/github/license/AnalogJ/lexicon :target: https://github.com/AnalogJ/lexicon/blob/master/LICENSE
.. contents:: Table of Contents :local:
.. tag: intro-begin
Why using Lexicon?
Lexicon provides a way to manipulate DNS records on multiple DNS providers in a standardized way.
Lexicon can be used as:
- a CLI tool:
.. code-block:: bash
# Create a TXT entry in domain.net zone hosted by CloudFlare
lexicon cloudflare create domain.net TXT --name foo --content bar
- or a Python library:
.. code-block:: python
# Create a TXT entry in domain.net zone hosted by CloudFlare
from lexicon.client import Client
from lexicon.config import ConfigResolver
config = ConfigResolver().with_env().with_dict({
"provider_name" : "cloudflare",
"domain": "domain.net",
})
with Client(config) as operations:
operations.create_record("TXT", "foo", "bar")
Lexicon was designed to be used in automation, specifically letsencrypt.
Generating Intranet & Private Network SSL Certificates using Lets Encrypt & Lexicon <http://blog.thesparktree.com/post/138999997429/generating-intranet-and-private-network-ssl>
_
Supported providers
Only DNS providers who have an API can be supported by lexicon
.
The current supported providers are:
.. This section is autogenerated and should not been modified directly. However you should add a reference to the provider API in the list below, using the following syntax: .. _provider: URL_API
.. tag: providers-table-begin
+-----------------+-----------------+-----------------+-----------------+-----------------+ | aliyun_ | aurora_ | azure_ | cloudflare_ | cloudns_ | +-----------------+-----------------+-----------------+-----------------+-----------------+ | cloudxns_ | conoha_ | constellix_ | ddns_ | digitalocean_ | +-----------------+-----------------+-----------------+-----------------+-----------------+ | dinahosting_ | directadmin_ | dnsimple_ | dnsmadeeasy_ | dnspark_ | +-----------------+-----------------+-----------------+-----------------+-----------------+ | dnspod_ | dnsservices_ | dreamhost_ | duckdns_ | dynu_ | +-----------------+-----------------+-----------------+-----------------+-----------------+ | easydns_ | easyname_ | euserv_ | exoscale_ | flexibleengine_ | +-----------------+-----------------+-----------------+-----------------+-----------------+ | gandi_ | gehirn_ | glesys_ | godaddy_ | googleclouddns_ | +-----------------+-----------------+-----------------+-----------------+-----------------+ | gransy_ | gratisdns_ | henet_ | hetzner_ | hostingde_ | +-----------------+-----------------+-----------------+-----------------+-----------------+ | hover_ | infoblox_ | infomaniak_ | internetbs_ | inwx_ | +-----------------+-----------------+-----------------+-----------------+-----------------+ | joker_ | linode_ | linode4_ | localzone_ | luadns_ | +-----------------+-----------------+-----------------+-----------------+-----------------+ | memset_ | misaka_ | mythicbeasts_ | namecheap_ | namecom_ | +-----------------+-----------------+-----------------+-----------------+-----------------+ | namesilo_ | netcup_ | nfsn_ | njalla_ | nsone_ | +-----------------+-----------------+-----------------+-----------------+-----------------+ | oci_ | onapp_ | online_ | ovh_ | plesk_ | +-----------------+-----------------+-----------------+-----------------+-----------------+ | pointhq_ | porkbun_ | powerdns_ | qcloud_ | rackspace_ | +-----------------+-----------------+-----------------+-----------------+-----------------+ | rage4_ | rcodezero_ | route53_ | safedns_ | sakuracloud_ | +-----------------+-----------------+-----------------+-----------------+-----------------+ | softlayer_ | timeweb_ | transip_ | ultradns_ | valuedomain_ | +-----------------+-----------------+-----------------+-----------------+-----------------+ | vercel_ | vultr_ | webgo_ | wedos_ | yandex_ | +-----------------+-----------------+-----------------+-----------------+-----------------+ | yandexcloud_ | zeit_ | zilore_ | zonomi_ | | +-----------------+-----------------+-----------------+-----------------+-----------------+
.. tag: providers-table-end
.. _aliyun: https://help.aliyun.com/document_detail/29739.html .. _arvancloud: https://www.arvancloud.ir/api/cdn/4.0 .. _aurora: https://www.pcextreme.com/aurora/dns .. _azure: https://docs.microsoft.com/en-us/rest/api/dns/ .. _cloudflare: https://api.cloudflare.com/#endpoints .. _cloudns: https://www.cloudns.net/wiki/article/56/ .. _cloudxns: https://www.cloudxns.net/support/lists/cid/17.html .. _conoha: https://www.conoha.jp/docs/ .. _constellix: https://api-docs.constellix.com/?version=latest .. _ddns: https://www.rfc-editor.org/rfc/rfc2136 .. _digitalocean: https://developers.digitalocean.com/documentation/v2/#create-a-new-domain .. _dinahosting: https://en.dinahosting.com/api .. _directadmin: https://www.directadmin.com/features.php?id=504 .. _dnsimple: https://developer.dnsimple.com/v2/ .. _dnsmadeeasy: https://api-docs.dnsmadeeasy.com/?version=latest .. _dnspark: https://dnspark.zendesk.com/entries/31210577-rest-api-dns-documentation .. _dnspod: https://support.dnspod.cn/support/api .. _dnsservices: https://dns.services/userapi .. _dreamhost: https://help.dreamhost.com/hc/en-us/articles/217560167-api_overview .. _duckdns: https://www.duckdns.org/spec.jsp .. _dynu: https://www.dynu.com/support/api .. _easydns: http://docs.sandbox.rest.easydns.net/ .. _easyname: https://www.easyname.com/en .. _euserv: https://support.euserv.com/api-doc/ .. _exoscale: https://community.exoscale.com/documentation/dns/api/ .. _flexibleengine: https://registry.terraform.io/providers/FlexibleEngineCloud/flexibleengine/latest/docs/data-sources/dns_zone_v2 .. _gandi: http://doc.livedns.gandi.net/ .. _gehirn: https://support.gehirn.jp/apidocs/gis/dns/index.html .. _glesys: https://github.com/glesys/api/wiki/ .. _godaddy: https://developer.godaddy.com/getstarted#access .. _googleclouddns: https://cloud.google.com/dns/api/v1/ .. _gransy: https://subreg.cz/manual/ .. _gratisdns: .. _henet: https://dns.he.net/ .. _hetzner: https://dns.hetzner.com/api-docs/ .. _hostingde: .. _hover: https://www.hover.com/ .. _infoblox: https://docs.infoblox.com/display/ilp/infoblox+documentation+portal .. _infomaniak: https://www.infomaniak.com .. _internetbs: https://internetbs.net/resellerregistrardomainnameapi .. _inwx: https://www.inwx.de/en/offer/api .. _joker: https://joker.com/faq/index.php?action=show&cat=39 .. _linode: https://www.linode.com/api/dns .. _linode4: https://developers.linode.com/api/docs/v4#tag/domains .. _localzone: .. _luadns: http://www.luadns.com/api.html .. _memset: https://www.memset.com/apidocs/methods_dns.html .. _misaka: https://misaka.io/dns/ .. _mythicbeasts: https://www.mythic-beasts.com/support/api/dnsv2 .. _namecheap: https://www.namecheap.com/support/api/methods.aspx .. _namecom: https://www.name.com/api-docs .. _namesilo: https://www.namesilo.com/api_reference.php .. _netcup: https://ccp.netcup.net/run/webservice/servers/endpoint.php .. _nfsn: .. _njalla: https://njal.la/api/ .. _nsone: https://ns1.com/api/ .. _oci: https://docs.oracle.com/en-us/iaas/Content/DNS/home.htm .. _onapp: https://docs.onapp.com/display/55api/onapp+5.5+api+guide .. _online: .. _ovh: https://api.ovh.com/ .. _plesk: https://docs.plesk.com/en-us/onyx/api-rpc/about-xml-api.28709/ .. _pointhq: https://pointhq.com/api/docs .. _porkbun: https://kb.porkbun.com/article/190-getting-started-with-the-porkbun-dns-api .. _powerdns: https://doc.powerdns.com/md/httpapi/api_spec/ .. _qcloud: https://cloud.tencent.com/document/product/1427/56194 .. _rackspace: https://developer.rackspace.com/docs/cloud-dns/v1/developer-guide/ .. _rage4: https://gbshouse.uservoice.com/knowledgebase/articles/109834-rage4-dns-developers-api .. _rcodezero: https://my.rcodezero.at/api-doc .. _route53: https://docs.aws.amazon.com/route53/latest/apireference/welcome.html .. _safedns: https://developers.ukfast.io/documentation/safedns .. _sakuracloud: https://developer.sakura.ad.jp/cloud/api/1.1/ .. _softlayer: https://sldn.softlayer.com/article/rest#http_request_types .. _timeweb: https://timeweb.cloud/api-docs .. _transip: https://api.transip.nl/rest/docs.html .. _ultradns: https://ultra-portalstatic.ultradns.com/static/docs/rest-api_user_guide.pdf .. _valuedomain: https://www.value-domain.com/service/api/ .. _vercel: https://vercel.com/docs/api#endpoints/dns .. _vultr: https://www.vultr.com/api/#tag/dns .. _webgo: https://www.webgo.de/ .. _wedos: https://www.wedos.com/cs/ .. _yandex: https://yandex.com/dev/domain/doc/reference/dns-add.html .. _yandexcloud: https://cloud.yandex.com/en/docs/dns/api-ref/DnsZone/ .. _zeit: .. _zilore: https://zilore.com/en/help/api .. _zonomi: http://zonomi.com/app/dns/dyndns.jsp
.. tag: intro-end
Documentation
Online documentation (user guide, configuration reference) is available in the Lexicon documentation
_.
For a quick start, please have a look in particular at the User guide
_.
.. _Lexicon documentation: https://dns-lexicon.readthedocs.io .. _User guide: https://dns-lexicon.readthedocs.io/en/latest/user_guide.html
Contributing
If you want to help in the Lexicon development, you are welcome!
Please have a look at the Developer guide
_ page to know how to start.
.. _Developer guide: https://dns-lexicon.readthedocs.io/en/latest/developer_guide.html
Licensing
- MIT
- Logo_: transform by Mike Rowe from the Noun Project
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