Skip to main content

SDK to facilitate Python integrations with Stark Sign

Project description

Stark Sign Python SDK - Beta

Welcome to the Stark Sign Python SDK! This tool is made for Python developers who want to easily integrate with our API. This SDK version is compatible with the Stark Sign API v2.

Introduction

Index

Supported Python Versions

This library supports the following Python versions:

  • Python 2.7
  • Python 3.4+

Stark Sign API documentation

Feel free to take a look at our API docs.

Versioning

This project adheres to the following versioning pattern:

Given a version number MAJOR.MINOR.PATCH, increment:

  • MAJOR version when the API version is incremented. This may include backwards incompatible changes;
  • MINOR version when breaking changes are introduced OR new functionalities are added in a backwards compatible manner;
  • PATCH version when backwards compatible bug fixes are implemented.

Setup

1. Install our SDK

1.1 To install the package with pip, run:

pip install starksign

1.2 To install from source, clone the repo and run:

python setup.py install

2. Setting up the environment

You must configure the SDK to use one of our two available environments:

  • sandbox: This is a testing environment where you can get to know and test your system's interactions with ours.
  • production: This is real World, where your actions will have a real impact on your operations.

To do this, assign it while your application is booting:

import starksign

starksign.environment = "sandbox"  # or production

On all following examples, we will assume a default user has been set.

3. Setting up the error language

The error language (and timeout) can also be set in the same way as the default user:

import starksign

starksign.language = "en-US"

Language options are "en-US" for English and "pt-BR" for Brazilian Portuguese. English is the default.

Signatures

There are 3 ways a party can sign a document:

1. Link signatures

Using this method, the signer will receive a link (by email, SMS, etc.), which will open the document link with a validated signature button. By reading the document and clicking on the button, the person's signature will be registered. This method doesn't require usage of this SDK and its functions.

2. Token signatures

Using this method, you are expected to provide an interface (via browser, app, etc.) to the signer, who will read the document, receive a token (via email, SMS, etc.) and then inform it to the interface to sign it.

3. Server signatures

Using this method, your service will receive a request on the informed endpoint. This request will carry a private key, which should be used to sign the document after its validation.

Usage

Here are a few examples on how to use the SDK. If you have any doubts, you can also use the built-in help() function to get more info on the desired functionality (for example: help(starksign.issuinginvoice.create))

Server signatures

If you need a server/system to automatically sign the documents, you can follow these steps:

1. Receive a SignatureRequest on your endpoint

If your system is expected to sign documents that are being generated, be prepared to receive calls to the informed endpoint and parse them accordingly before you proceed with the signature:

import starksign

response = listen()  # this is the method you made to get the events posted to your webhook endpoint

signature_request = starksign.signaturerequest.parse(
    content=response.data.decode("utf-8"),
    signature=response.headers["Digital-Signature"],
)

print(signature_request)

2. Get the document data before signing

Once you receive a signature request, fetch the referenced document to check it out before signing it:

import starksign

document = starksign.document.get(signature_request.document_id)

print(document)

3. Sign the document

Once you have the SignatureRequest and Document and your system understands the signature is due, you can sign it:

import starksign

signature = starksign.document.sign(
  id=document.id,
  content=document.content,
  signer_id=signature_request.signer_id,
  private_key=signature_request.private_key,
)

print(signature)

Token signatures

If you expect your users to sign documents using the tokens they receive via email, SMS, etc., your interface (which should already have the document data loaded) should be able to receive their tokens and sign on their behalf by doing this:

1. Sign the document

This is the same method used before, but the token is provided instead of the private_key:

import starksign

# since your interface is asking for a specific document's signature, it should already know the document and signer
document = get_document()  # this is not an SDK function, you should implement this to get the Document data 
signer = get_signer()  # this is not an SDK function, you should implement this to get the Signer data

token = get_user_input()  # this is not an SDK function, you should implement this to get the user input

signature = starksign.document.sign(
  id=document.id,
  content=document.content,
  signer_id=signer.id,
  token=token,
)

print(signature)

Handling errors

The SDK may raise one of four types of errors: InputErrors, InternalServerError, UnknownError, InvalidSignatureError

InputErrors will be raised whenever the API detects an error in your request (status code 400). If you catch such an error, you can get its elements to verify each of the individual errors that were detected in your request by the API. For example:

import starksign

try:
    signature = starksign.document.sign(
        id="7a8361ec097543daa48acd5312471cf5",
        content="<meta charset='utf-8'><page size='A4'>Test</page>",
        signer_id="2345234523452345",
        token="abcd1234",
    )
except starksign.error.InputErrors as exception:
    for error in exception.errors:
        print(error.code)
        print(error.message)

InternalServerError will be raised if the API runs into an internal error. If you ever stumble upon this one, rest assured that the development team is already rushing in to fix the mistake and get you back up to speed.

UnknownError will be raised if a request encounters an error that is neither InputErrors nor an InternalServerError, such as connectivity problems.

InvalidSignatureError will be raised specifically by starksign.event.parse() when the provided content and signature do not check out with the Stark Sign public key.

Help and Feedback

If you have any questions about our SDK, just send us an email. We will respond you quickly, pinky promise. We are here to help you integrate with us ASAP. We also love feedback, so don't be shy about sharing your thoughts with us.

Email: help@starkbank.com

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

starksign-0.0.1.tar.gz (12.6 kB view details)

Uploaded Source

File details

Details for the file starksign-0.0.1.tar.gz.

File metadata

  • Download URL: starksign-0.0.1.tar.gz
  • Upload date:
  • Size: 12.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.10.3

File hashes

Hashes for starksign-0.0.1.tar.gz
Algorithm Hash digest
SHA256 131ae617950929235b1fc2df3f59047882eac8c8dae5f7544a4f71e6a161fb5f
MD5 ce4b1f320da68d72064bd815ef09d127
BLAKE2b-256 3894671fac03cddbafde3a8ec490ed800ab1e0c438613d1c8c591e89e0ab5b84

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page