Knish.IO Python API Client
Project description
Knish.IO Python Client
This is an experimental Python implementation of the Knish.IO API client. Its purpose is to expose class libraries for building and signing Knish.IO Molecules, composing Atoms (presently "A", "C", "M", "U", "I", "T" and "V" isotopes are supported), and generating Wallet addresses (public keys) and private keys as per the Knish.IO Technical Whitepaper.
Getting Started
pip install knishio-client-python
- Inside your application code,
from knishioclient.models import Molecule, Wallet
- Build a 2048-character user secret via your preferred methodology (random string?).
- Initialize a wallet with
wallet = Wallet(secret, token)
You can also specify a third, optional position
argument represents the private key index (hexadecimal), and must NEVER be used more than once. It will be generated randmly if not provided.
A fourth argument, salt_length
, helps tweak the length of the random position
, if the parameter is not provided.
The token
argument (string) is the slug for the token being transacted with. Knish.IO anticipates user's personal metadata being kept under the USER
token.
Building Your Molecule
- Build your molecule with
molecule = Molecule(secret, source_wallet, remainder_wallet, cell_slug)
Thecell_slug
argument represents the slug for your Knish.IO cell. It's meant to segregate molecules of one use case from others. Leave it null if not sure. - For a "M"-type molecule, build your metadata as an array of objects, for example:
data = [
{
'key': 'name',
'value': 'foo'
},
{
'key': 'email',
'value': 'bar'
},
#...
]
or
data = {
'name': 'foo',
'email': 'bar',
#...
}
- Initialize the molecule as "M"-type:
molecule.init_meta(data, meta_type, meta_id)
Themeta_type
andmeta_id
arguments represent a polymorphic key to whatever asset you are attaching this metadata to. - Sign the molecule with the user secret:
molecule.sign()
- Make sure everything checks out by verifying the molecule:
from knishioclient.models import Molecule, Wallet
source_wallet = Wallet(secret, token)
remainder_wallet = Wallet(secret, token)
molecule = Molecule(secret, source_wallet, remainder_wallet, cell_slug)
molecule.init_meta(data, meta_type, meta_id)
molecule.sign()
if molecule.check():
#... Do stuff? Send the molecule to a Knish.IO node, maybe?
Broadcasting
- Knish.IO nodes use GraphQL to receive new molecules as a Mutation. The code for the mutation is as follows:
mutation MoleculeMutation($molecule: MoleculeInput!) {
ProposeMolecule(
molecule: $molecule,
) {
molecularHash,
height,
depth,
status,
reason,
reasonPayload,
createdAt,
receivedAt,
processedAt,
broadcastedAt
}
}
- Use your favorite GraphQL client to send the mutation to a Knish.IO node with the molecule you've signed as the only parameter.
- The
status
field of the response will indicate whether the molecule was accepted or rejected, or if it's pending further processing. Thereason
andreasonPayload
fields can help further diagnose and handle rejections.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for knishioclient-0.1.52-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fdff70bd511bb6bc9d1cceacb3918fe0d6b7cf5c07bb3c9289cd60a34672acb1 |
|
MD5 | 4e8efa5f9fcdf0ead1000a227ef2e259 |
|
BLAKE2b-256 | 6038910d4718227053f5b59db086f28869f937c741fd808797fca9f334df0393 |