Skip to main content

Apple CloudKit server-to-server support for the requests Python library.

Project description

|image0| |image1|

|CI Status| |Version|

This project provides an authentication handler for Apple’s CloudKit
server-to-server API for the requests Python library. In English, this
means that this library lets you interact with CloudKit with Python in a
server environment. It just has two
dependencies–\ `requests <>`__
and python-ecdsa–and lets you skip all of the dull and boring
cryptographic signing steps when authenticating with CloudKit on your
own. While the underlying code is pretty straightforward, there was no
correct code sample available online that described how to do this–but
now there is!


requests-cloudkit is available for download through the Python Package
Index (PyPi). You can install it right away using pip or easy_install.

.. code:: bash

pip install requests-cloudkit


requests-cloudkit provides an authentication handler that can be passed
directly to the requests library to authenticate requests to the
CloudKit API. Before working with the CloudKit server-to-server API,
you’ll first need to follow Apple’s instructions to generate a
certificate and a server-to-server key (see `Accessing CloudKit Using a
Key <>`__).

Once you have these values, just plug them into a CloudKitAuth object,
which you can use with requests to interface with CloudKit. E.g.:

.. code:: pycon

>>> import requests
>>> from requests_cloudkit import CloudKitAuth
>>> auth = CloudKitAuth(key_id=YOUR_KEY_ID, key_file_name=YOUR_PRIVATE_KEY_PATH)
>>> requests.get("[version]/[container]/[environment]/public/zones/list", auth=auth)

Using Requests-CloudKit with RestMapper

requests-cloudkit can also be used with
`python-restmapper <>`__
to integrate directly with the CloudKit API.

.. code:: pycon

>>> CloudKit = restmapper.RestMapper("[version]/[container]/[environment]/")

Instantiate a cloudkit instance using your CloudKit server-to-server key
ID and provide the path to the private key file.

.. code:: pycon

>>> cloudkit = CloudKit(auth=CloudKitAuth(key_id=YOUR_KEY_ID, key_file_name=YOUR_KEY_FILE))

Now, you can start making requests to the CloudKit API using a nice
attribute syntax.

.. code:: pycon

>>> response = cloudkit.public.zones.list()

The above will hit[version]/[container]/[environment]/public/zones/list.

If you want to pass in body data for a POST, provide a single argument
to the call to the API, and specify “POST” as the first attribute (note:
this argument expects a *str* value, so if you want to pass JSON, use
``json.dumps`` to encode it into a string). I.e.

.. code:: pycon



.. code:: pycon


For the full list of CloudKit Server-to-Server API capabilities,
reference `Apple’s developer
documentation <>`__.


If you like this library, or need help implementing it, just send us an

.. _license-licenselicense-imagelicense-url:

License |License|

Apache License, Version 2.0. See `LICENSE <license-url>`__ for details.

.. raw:: html

.. |downloads| image::
.. _downloads:

.. |image0| image:: meta/repo-banner.png
.. |image1| image:: meta/repo-banner-bottom.png
.. |CI Status| image::
.. |Version| image::
.. |License| image::

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release. See tutorial on generating distribution archives.

Built Distribution

requests_cloudkit-1.0.1-py2.py3-none-any.whl (8.6 kB view hashes)

Uploaded py2 py3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page