Skip to main content
|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 <https://github.com/kennethreitz/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!

Installation
------------

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

Usage
-----

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
Server-to-Server
Key <https://developer.apple.com/library/ios/documentation/DataManagement/Conceptual/CloutKitWebServicesReference/SettingUpWebServices/SettingUpWebServices.html#//apple_ref/doc/uid/TP40015240-CH24-SW6>`__).

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("https://api.apple-cloudkit.com/database/[version]/[container]/[environment]/public/zones/list", auth=auth)

Using Requests-CloudKit with RestMapper
---------------------------------------

requests-cloudkit can also be used with
`python-restmapper <https://github.com/lionheart/python-restmapper>`__
to integrate directly with the CloudKit API.

.. code:: pycon

>>> CloudKit = restmapper.RestMapper("https://api.apple-cloudkit.com/database/[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
https://api.apple-cloudkit.com/database/[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

>>> cloudkit.POST.my.request(data)

Or:

.. code:: pycon

>>> cloudkit.POST.my.request(json.dumps(json_payload))

For the full list of CloudKit Server-to-Server API capabilities,
reference `Apple’s developer
documentation <https://developer.apple.com/library/ios/documentation/DataManagement/Conceptual/CloutKitWebServicesReference/Introduction/Introduction.html#//apple_ref/doc/uid/TP40015240-CH1-SW1>`__.

Support
-------

If you like this library, or need help implementing it, just send us an
email: hi@lionheartsw.com.

.. _license-licenselicense-imagelicense-url:

License |License|
-----------------

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

.. raw:: html

<!--
.. |downloads| image:: https://img.shields.io/pypi/dm/requests-cloudkit.svg?style=flat
.. _downloads: https://pypi.python.org/pypi/requests-cloudkit
-->

.. |image0| image:: meta/repo-banner.png
.. |image1| image:: meta/repo-banner-bottom.png
:target: https://github.com/lionheart/requests-cloudkit/blob/master/https://lionheartsw.com/
.. |CI Status| image:: https://img.shields.io/travis/lionheart/requests-cloudkit.svg?style=flat
:target: https://github.com/lionheart/requests-cloudkit/blob/master/https://travis-ci.org/lionheart/requests-cloudkit.py
.. |Version| image:: https://img.shields.io/pypi/v/requests-cloudkit.svg?style=flat
:target: https://github.com/lionheart/requests-cloudkit/blob/master/https://pypi.python.org/pypi/requests-cloudkit
.. |License| image:: http://img.shields.io/pypi/l/requests-cloudkit.svg?style=flat
:target: https://github.com/lionheart/requests-cloudkit/blob/master/LICENSE


Metadata

Release files for requests-cloudkit 1.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distribution (wheel)

Table of built distributions (wheels) for requests-cloudkit 1.0.1
File Interpreter ABI Platform
requests_cloudkit-1.0.1-py2.py3-none-any.whl Python 3, Python 2 none any Details

Release files / requests_cloudkit-1.0.1-py2.py3-none-any.whl

Download URL requests_cloudkit-1.0.1-py2.py3-none-any.whl
Size 8.6 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
15dd1158cfff24299eda106a2fe3dbac218ac8abc0cf5797fb8ab8469387a2b7
BLAKE2b-256 checksum
How to use checksums
e3e49d795ed267c4dd8f7ddb8551e6ef56f35a8904b4c4bfd1861d6a4b807143
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

1.0.1 This release

1 release file

1.0.0

1 release file

0.1.5

1 release file

0.1.3

1 release file

0.1.2

1 release file

0.1.1

1 release file

0.1.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page