Skip to main content

Python

At a Glance#

  • DIDKit's Python binaries can be installed directly from pip/pypi (instructions below); for manual/custom builds, see the sub-repo README.md file.
  • For a few clear examples see the Syntax section below.
  • The syntax is quite similar to the Rust library, so for a more systematic reference, you can read the Rust documentation.

Installation#

Make sure you have the latest versions of pip and PyPA’s build installed:

sudo apt install -y python3-pip python3-virtualenv
python3 -m pip install --upgrade pip build

Build DIDKit (latest release):

cargo build --release

Build the package

python3 -m build

Install the package using the provided setup.cfg file:

python3 -m pip install dist/didkit-`cat setup.cfg | grep version | cut -d' ' -f3`-*.whl

Syntax#

To use DIDKit in Python, import the didkit library and manipulate the didkit object as you would any other. It contains all the same methods and properties as the didkit object in Rust, so you can refer to the Rust docs for an overview of the core structure of DIDKit as a library.

The method issueCredential, for example, takes all the properties you would expect, as strings (mind the escape quotes!) and returns a credential as a JSON object that the user then .dumps or .loads. See this example from the Python-Flask example project:

credential = didkit.issueCredential(
credential.__str__().replace("'", '"'),
didkit_options.__str__().replace("'", '"'),
key)
return json.loads(credential)

Examples#

ToolExample
Django web frameworkexample in GitHub
Flask web microframeworkexample in GitHub