Coder Social home page Coder Social logo

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

Before running a function, you need to first get an access token (<AUTH_TOKEN>) with the Cape CLI by running cape login. Once logged into Cape, your token can be found in the ~/.config/cape/auth file. The access token will be used when instantiating Cape client. If access_token attribute is None, it will try to load automatically the access token from your config file. Then you'll obtain a function id (<FUNCTION_ID>) and function hash (<FUNCTION_HASH>) once you have deployed a function with cape deploy.

run

Run is used to invoke a function once with a single input. By default, inputs and outputs are expected to be bytes. However you can easily serialize and deserialize inputs and outputs, using Serdio. To learn more about Serdio, check out this example. Cape returns a function hash to the user during deploy. If function hash is specified to None, then verification of function hash will not occur. It is encouraged to always provide the desired function hash for security.

Example run_echo.py:

from pycape import Cape
from pycape import FunctionRef

client = Cape(url="wss://enclave.capeprivacy.com")
function_id = "X9rgtUVm6yYrPMZamBWTZY"
function_hash = "cbca8c9f7ac41138935018c3f45cd16d1abfbe15a37b1fc09a11dfbc3d44b447"
f = FunctionRef(function_id, function_hash)
result = client.run(f, b"Hello!")
print(result.decode())
>> hello!

invoke

Invoke is used to run a function repeatedly with multiple inputs. It gives you more control over the lifecycle of the function invocation.

Example invoke_echo.py:

from pycape import Cape
from pycape import FunctionRef

client = Cape(url="wss://enclave.capeprivacy.com")
function_id = "X9rgtUVm6yYrPMZamBWTZY"
function_hash = "cbca8c9f7ac41138935018c3f45cd16d1abfbe15a37b1fc09a11dfbc3d44b447"
f = FunctionRef(function_id, function_hash)
client.connect(f)
result = client.invoke(b"Hello Alice!")
print(result.decode())
>> Hello Alice!
result = client.invoke(b"Hello Bob!")
print(result.decode())
>> Hello Bob!
result = client.invoke(b"Hello Carole!")
print(result.decode())
>> Hello Carole!

(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)

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.