Use the official Python wrapper provided by Cloudflare. This was built when v4 of the API was very fresh and the official wrapper had not existed yet.
CloudConnect is a simple pure python interface for v4 of the CloudFlare API.
At the moment it mostly provides a thin wrapper around CloudFlare API connections. Each wrapped call returns the JSON data as a python dict.
Over time it will also include commands that complement and extend the current CF API's capabilities.
A current example is listing DNS records based on domain name, rather than just by ID.
- Python 2.7
- Python 3.5+
This project is currently under development. Pull requests and suggested code improvements are welcome.
$ git clone https://github.com/timworx/cloudconnect.git
$ python setup.py install
Or via pip with:
$ pip install git+git://github.com/timworx/cloudconnect.git
Calls to the CloudFlare API with CloudConnect will return a dict of the JSON data returned (unless otherwise noted).
Initializing CloudConnect
>>> from cloudconnect import CloudConnect
>>> cf = CloudConnect('[email protected]', 'd2gYOURoAPIoKEYo24fmdsf')
Create a new zone (add a domain) with create_zone
and skip the automagic record grabbing by CloudFlare.
>>> from cloudconnect import CloudConnect
>>> cf = CloudConnect('[email protected]', 'd2gYOURoAPIoKEYo24fmdsf')
>>> cf.create_zone('mydomain.com', jump_start=False)
{u'errors': [],
u'messages': [],
u'result': {u'status': u'pending',
u'original_name_servers': [u'ns1.com', u'ns2.com'],
u'original_dnshost': None,
u'name': u'anotherdomain.com',
u'owner': {u'type': u'user',
u'id': u'd2gYOURoAPIoKEYo24fmdsf',
u'email': u'[email protected]'},
u'original_registrar': None,
u'paused': False,
u'modified_on': u'2015-06-17T21:37:45.967464Z',
u'created_on': u'2015-06-17T21:37:45.930702Z',
...
A Note About **kwargs
You can use **kwargs
to pass arguments/parameters that are not required by Cloudflare. For example, notice how jump_start=False
is passed above.
cf = Cloudconnect('[email protected]', 'd2gYOURoAPIoKEYo24fmdsf')
cf.create_zone(domain, **kwargs)
cf.get_zone_id(domain)
cf.create_dns_record(zone_id, r_type, name, content, **kwargs)
cf.update_dns_record(zone_id, rec_id, **kwargs)
cf.list_dns_records(zone_id, **kwargs)
cf.delete_dns_record(zone_id, rec_id)
cf.domain_list_dns_records(domain, **kwargs)
you can subclass CloudConnect to create another layer of project specific abstraction for API calls.
For example, let's say that you had two records to apply to your domains, both proxied by CloudFlare.
>>> from cloudconnect import CloudConnect
>>> class MyCloudConnect(CloudConnect):
>>> def set_the_records(self, domain):
>>> zone_id = self.get_zone_id(domain)
>>> rec1 = self.create_dns_record(zone_id, 'A', '@', '127.0.0.1', proxied=True)
>>> rec2 = self.create_dns_record(zone_id, 'CNAME', 'www', 'mydomain.com', proxied=True)
>>> return rec1, rec2