{"id":26084154,"url":"https://github.com/capeprivacy/functions","last_synced_at":"2025-04-12T00:43:18.079Z","repository":{"id":57903785,"uuid":"503843375","full_name":"capeprivacy/functions","owner":"capeprivacy","description":"Sample functions for Cape Privacy","archived":false,"fork":false,"pushed_at":"2023-09-08T12:24:15.000Z","size":47541,"stargazers_count":20,"open_issues_count":2,"forks_count":3,"subscribers_count":5,"default_branch":"main","last_synced_at":"2025-04-12T00:43:10.064Z","etag":null,"topics":["confidential-computing","enclaves","nitro","nitro-enclaves","python"],"latest_commit_sha":null,"homepage":"https://docs.capeprivacy.com","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/capeprivacy.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-06-15T16:29:58.000Z","updated_at":"2024-01-18T22:57:11.000Z","dependencies_parsed_at":"2025-03-09T04:50:43.109Z","dependency_job_id":null,"html_url":"https://github.com/capeprivacy/functions","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/capeprivacy%2Ffunctions","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/capeprivacy%2Ffunctions/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/capeprivacy%2Ffunctions/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/capeprivacy%2Ffunctions/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/capeprivacy","download_url":"https://codeload.github.com/capeprivacy/functions/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248501951,"owners_count":21114681,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["confidential-computing","enclaves","nitro","nitro-enclaves","python"],"created_at":"2025-03-09T04:50:39.017Z","updated_at":"2025-04-12T00:43:18.053Z","avatar_url":"https://github.com/capeprivacy.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Cape Functions\n\n## Getting Started\n\nTo run these functions with Cape, you need to first install the [Cape CLI](https://docs.capeprivacy.com/getting-started#install-the-cape-cli). Then you will have to sign up from [Cape's website](https://capeprivacy.com/) or using the CLI:\n```\ncape signup\n``` \n\nThese examples can be also executed from Cape's SDKs: [cape-js](https://docs.capeprivacy.com/sdks/javascript-sdk) and [pycape](https://pydocs.capeprivacy.com/). If you execute these functions from one of the SDK, you will have to generate a [personal access token](https://docs.capeprivacy.com/reference/user-tokens). This can be done from [Cape's website](https://capeprivacy.com/) or from the CLI:\n```\ncape token create --name my-token --description 'for use in the javascript sdk'\n```\n\n## Examples\n\n### Echo\n\nA simple function that returns whatever you send it. Check out the folder [echo](./echo/) to learn how to deploy this function. To invoke this function, you can run the following:\n\n```\ncape run capedocs/echo -f echo/input.echo.data\n```\n\n### Isprime\n\nA simple function checking if your number is prime or not. Check out the folder [isprime](./isprime/) to learn how to deploy this function. To invoke this function, you can run the following:\n\n```\ncape run capedocs/isprime -f isprime/input.isprime.data\n```\n\n### Pendulum\nIn this example, we show how to run a function requiring a dependency. The function simply returns the current time based on a specific timezone using the [Pendulum](https://pendulum.eustace.io/) library. To learn how to deploy this function, check out the folder [pendulum](./pendulum/). To invoke the function, invoke:\n\n```\ncape run capedocs/pendulum Europe/Paris \n```\n\n### Numpy Stats\nA simple example with numpy dependencies and using [pycape](https://github.com/capeprivacy/pycape) and [serdio.lift_io](https://pydocs.capeprivacy.com/serdio.io_lifter.html#serdio.io_lifter.lift_io) to handle automatic serialization/deserialization of Cape function input/outputs. You can learn how to deploy this function by checking the folder [np-stats](./np-stats/). You can run the function as follow after install installing in a virtual environment in `np-stats/requirements.txt`:\n\n```\nexport TOKEN=\u003cYOUR TOKEN\u003e\nexport FUNCTION_ID=capedocs/np-stats\npython np-stats/run.py\n```\n\n### Secure Search\nSimulates a cybersecurity search function, where the IP addresses you are interested in need to remain private but the data/logs you are searching might be public. You can learn more about this function by checking the folder [secure-search](./secure_search/).\n\n```\ncape run capedocs/secure-search  -f secure_search/input.search.data\n```\n\n### Leader Election\nDemos how a secure trusted execution environment like Cape can be leveraged in consensus in order to guarantee fairness. Details on how to run this example can be found\n[here](./leader-election).\n\n\n### Hide-and-seek\nTo learn more about the confidential hide-and-seek example, you can check the folder [hide_and_seek](./hide_and_seek).\n\n\n### Mortgage\nThis application is a mortgage calculator that computes if an applicant is eligible for a mortgage. To learn how to deploy this application, you can check out the folder [mortgage](./mortgage). To call this function, you can run:\n```\ncape run capedocs/mortgage -f mortgage/input.mortgage.json\n```\n\n## Machine Learning Examples\n\n### Image Classification Inference with ONNX\n\nTo learn how you can deploy and invoke an image classification model using the [onnxruntime](https://onnxruntime.ai/), you can check the [capeprivacy/image-classification-onnx](image-classification-onnxhttps://github.com/capeprivacy/image-classification-onnx) repository.\n\n\n### Image Classification Inference with tflite\nThis example demonstrates how to deploy and invoke an image classification model with [tflite](https://www.tensorflow.org/lite). To learn how to deploy this application, you can check out the folder [image-classification](./image_recognition). To invoke the model, run:\n\n```\ncape run capedocs/image-recognition -f image_recognition/coffee.jpg\n\n('Image Label is :', 'espresso', ', with Accuracy :', 84.38, '%.')\n```\n\n### Sentiment Analysis Inference with tflite\nThis example demonstrates how you can deploy and invoke a sentiment analysis model with [tflite](https://www.tensorflow.org/lite). To learn how to deploy this application, you can check out the folder [sentiment_analysis](./sentiment_analysis). To invoke the model, simply run:\n\n```\ncape run capedocs/sentiment-analysis -f sentiment_analysis/input.pos.data\n\n('The sentiment is: ', 'positive', ' with a probability of ', 78.08290123939514, '%.')\n```\n\n### Training and Inference with Scikit-Learn.\nYou can check the following examples to learn about how to deploying and invoke machine learning models with Scikit-Learn:\n- [credit_card_fraud_detection](./credit_card_fraud_detection/): performs secure inference to classify credit card transactions as fraudulent or legitimate.\n- [logistic_regression_sklearn](./logistic_regression_sklearn/): securely train an Sklearn logistic regression model on the breast cancer dataset.\n- [batch_training](./batch_training/): shows how to perform batch training with Sklearn model.\n\n\n# Invoke Cape's Confidential Services\n### Invoke Cape's Confidential OCR Service from SDKs\n\nThis example shows you how you can run the [Cape's confidential optical character recognition service](https://docs.capeprivacy.com/cape-hosted/ocr) from the SDKs: [cape-js](https://docs.capeprivacy.com/sdks/javascript-sdk) and [pycape](https://pydocs.capeprivacy.com/).\n\nFor this example, we will run the OCR on the PDF `./ocr/claude_shannon.pdf`.\n\n**From cape-js:**\n\nBefore invoking the OCR, set the environment variable `CAPE_AUTH_TOKEN` to your [personal access token](https://docs.capeprivacy.com/reference/user-tokens). \n```\nexport CAPE_AUTH_TOKEN=\"your cape auth token\"\n```\n\nTo run the OCR from cape-js on the PDF, from the [ocr folder](./ocr), run:\n```\nnode run_ocr.mjs\n```\n\nTo encrypt the PDF with [cape.encrypt](https://docs.capeprivacy.com/tutorials/encrypting#cape-encrypt), then invoke the OCR on the encrypted PDF, run:\n```\nnode encrypt_run_ocr.mjs\n```\n\n**From pycape:**\n\nBefore invoking the OCR, set the environment variable `CAPE_AUTH_TOKEN` to your [personal access token](https://docs.capeprivacy.com/reference/user-tokens). \n\n```\nexport CAPE_AUTH_TOKEN=\"your cape auth token\"\n```\n\nTo run the OCR from pycape on the PDF, from the [ocr folder](./ocr), run:\n```\npython run_ocr.py\n```\n\nTo encrypt the PDF with [cape.encrypt](https://docs.capeprivacy.com/tutorials/encrypting#cape-encrypt), then invoke the OCR on the encrypted PDF, run:\n```\npython encrypt_run_ocr.py\n```\n\n \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcapeprivacy%2Ffunctions","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcapeprivacy%2Ffunctions","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcapeprivacy%2Ffunctions/lists"}