GithubHelp home page GithubHelp logo

capeprivacy / pycape Goto Github PK

View Code? Open in Web Editor NEW
23.0 8.0 3.0 301 KB

The Cape Privacy Python SDK

Home Page: https://pydocs.capeprivacy.com

License: Apache License 2.0

Makefile 2.45% Python 97.55%
confidential-computing nitro python nitro-enclaves

pycape's Introduction

PyCape

The Cape SDK for Python is a library that provides a simple way to interact with the Cape Privacy API.

Table of Contents
  1. Installation
  2. Usage
  3. Contributing

Installation

Prerequisites

  • Python 3.7+
  • pip
  • Make (if installing from source)

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.

(back to top)

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.

(back to top)

pycape's People

Contributors

bendecoste avatar chrisfriesen avatar ekloberdanz avatar eric-capeprivacy avatar gavinuhma avatar jlapierre avatar justin1121 avatar jvmncs avatar miiklay avatar yanndupis avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pycape's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.