PyCape
The Cape SDK for Python is a library that provides a simple way to interact with the Cape Privacy API.
Table of Contents
Installation
Prerequisites
We recommend that you use a Python "Virtual Environment" when installing pycape.
Install via pip
You can install the current release with:
pip install pycape
Install from source
To install the library from source and all of its dependencies, run:
git clone https://github.com/capeprivacy/pycape.git
cd pycape
make install-release
Usage
To run a function, you need to first deploy a function and generate a personal access token. You can deploy a function with the Cape CLI by running cape deploy. cape deploy will return a function ID and a checksum. Non-CLI users can still consume the deployed function from the SDK as long as they have a copy of the deployer's personal access token. You can checkout the examples repository to see the process end to end.
run
Run is used to invoke a function once with a single input. A connection to a Cape function is created, then terminated upon completion (no set up or tear down is required). If you wish to invoke the same function multiple times without terminating the connection between calls, please see invoke. By default, inputs and outputs are expected to be bytes.
Note: You can optionally use Serdio to help with serialization and deserialization of inputs and outputs. To learn more, please check out this example.
Example run_echo.py:
from pycape import Cape
cape = Cape(url="https://app.capeprivacy.com")
token: str = "eyJhbGci..." # full token omitted for brevity
f = cape.function("pycape-dev/echo")
t = cape.token(token)
result = client.run(f, t, b"Hello!")
print(result.decode())
# Hello!
invoke
Invoke is used to run a function repeatedly with multiple inputs. The connection to your Cape function is not terminated between invocations. It gives you more control over the lifecycle, and can be more efficient. Prior to calling invoke, connect to your function and then close it when you are finished. You can also call invoke inside of a Cape.function_context, which will handle connecting and closing the connection for you. See the docs for a usage example.
Example invoke_echo.py:
from pycape import Cape
cape = Cape(url="https://app.capeprivacy.com")
token: str = "eyJhbGci..." # full token omitted for brevity
f = cape.function("pycape-dev/echo")
t = cape.token(token)
cape.connect(f, t)
result = cape.invoke(b"Hello Alice!")
print(result.decode())
# Hello Alice!
result = cape.invoke(b"Hello Bob!")
print(result.decode())
# Hello Bob!
result = cape.invoke(b"Hello Carole!")
print(result.decode())
# Hello Carole!
cape.close()
Please note that there is a 60-second inactivity timeout on the enclave connection. You may need to monitor the connection status and reconnect if there is a significant wait between inputs.
Contributing
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Please make sure to update tests as appropriate.
Read more about how to contribute to the Cape SDK in CONTRIBUTING.
Metadata
Release files for pycape 3.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pycape-3.1.1.tar.gz | 34.2 kB | Without provenance | Details for pycape-3.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pycape-3.1.1-py3-none-any.whl | Python 3 | none | any | Details for pycape-3.1.1-py3-none-any.whl |
Total release size: 71.5 kB
Release files / pycape-3.1.1.tar.gz
| Download URL | pycape-3.1.1.tar.gz |
|---|---|
| Size | 34.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b7e77eb28776bd15aa814b04c3a7ca848ea74224943e231555c7d4014fc8cda5
|
|
BLAKE2b-256 checksum How to use checksums |
a5f5b6407ab628397f6861dce7a2dc1b1081bf3a474a78edcff8d200cd6ad135
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.10.10
|
Release files / pycape-3.1.1-py3-none-any.whl
| Download URL | pycape-3.1.1-py3-none-any.whl |
|---|---|
| Size | 37.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b147aef502f6f654bc07902eb48351c5affaa650f13f1b860f22bf467cb79d52
|
|
BLAKE2b-256 checksum How to use checksums |
dd193c3cf2a70231ab7932cc7674c5c857c455dc591aa5830e6b97628abef60e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.10.10
|
Security for pycape 3.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.