1.0.0 • Published 1 year ago

@xc-ventures/xc-platform-documents v1.0.0

Weekly downloads
-
License
ISC
Repository
github
Last release
1 year ago

Documents

This is a python package to generate Google Docs and Sign Now documents.

Dev

Prerequisites

  • Python 3
  • Key for the Google Service Account (with access to Google Docs APIs). The json must be in root folder, named key.json
  • A Sign Now Sandbox account with an API key. .env file must be setup using .env.template
  • We recommend to use a virtual environment for python. There are many different tools to do that, but here, we will demonstrate with VirtualEnv

How to get started

  1. Let's start by creating a new virtual environment in the root of this repo. You shouldn't have to execute that again, unless you reset it.
python -m venv venv
  1. To start the virtual env (macOS):
source venv/bin/activate
  1. Now it's time to install all the dependencies to run this project. You won't need to execute that again, unless you reset your virtual env or the requirements changed.
pip install -r requirements.txt
  1. To run the project
python start.py

Tests

To run the unit tests, run this command line in your virtual env.

python -m pytest

Tips

Inside the virtual env, if you want to quit it:

$ deactivate

Installation

Using pip, it is possible to install the tools in this repo as a package so you can import them in other projects.

Prerequisites

  • Same prerequisites as mentionned above
  • Active SSH key pointing to repo with read access

How to install

pip install git+ssh://git@bitbucket.org/decksign/documents.git

You can specify a version using git tags. E.g.:

pip install git+ssh://git@bitbucket.org/decksig/documents.git@0.1.0

Templating Guidelines

The Google Doc templates we use with this repo must respect a certain nomenclature in order to work properly.

Variables

Variables must be defined with doubled curly brackets, like so:

Hello World, my name is {{first_name}}!

Here, first_name would be the var name.

Signature

Signature tags are for Google Docs that will be uploaded to Sign Now. They represent a full signature. They must be defined with doubled brackets and a role, like so:

Signature:

[[signature:ceo]]
CEO

Here, the role would be ceo.

Initials

Initials tags are for Google Docs that will be uploaded to Sign Now. They represent an initials. They must be defined with doubled brackets and a role, like so:

Initials:

[[initials:ceo]]
CEO

Here, the role would be ceo.

Note about Signature and Initials

In the process to uploading it to Sign Now, this package will update the Google Doc to replace the tags with a line of the same size of the tag itself. It is possible to make the line bigger by adding "_" chars following by a ":" in the first part of the tag, like so:

[[_______:signature:ceo]]

[[________:initials:ceo]]

Documentation

Class Document

This class provides a few tools allowing you to manipulate Google Docs templates (enter data), copy, share it. You can also use this class to upload PDF version of that Google Doc to Sign Now and invite people to sign it.

from documents import Document

Constructor args

nametyperequireddescription
google_doc_idstrNoThe document ID of the Google Doc we want to fetch. If not present property google_doc will be None.
signnow_doc_idstrNoThe document ID of the Sign Now Document we want to fetch. If not present property signnow_doc will be None.

Properties

nametypedescription
google_docGoogleDocThe Google Doc instance. Default to None.
signnow_docSignNowDocumentThe Sign Now Document instance. Default to None.

methods

namereturn typedescriptionargs
init_google_docNoneInstanciate the property google_doc with the specified id. Will overwrite the instanciation done the constructorgoogle_doc_id (str) The document ID of the Google Doc
init_signnow_docNoneInstanciate the property signnow_doc with the specified id. Will overwrite the instanciation done the constructorsignnow_doc_id (str) The document ID of the Sign Now Document
create_google_docNoneCreates a new empty Google Doc to instanciate the property google_doc withtitle (str) The title of the new Google Doc
shareNoneGives writer (Read/Write) role to the specified usersrecipients (Liststr) The emails of the users to give access to.
moveNoneMoves the google_doc into the specified folder.folder_id (str) The Google Drive Folder ID to move the Google Doc to.
lockNoneUpdates the google_doc file to be Read-Only
unlockNoneUpdates the google_doc file to disable the Read-Only mode
copy_with_dataGoogleDocCreate a new Google Doc by copying google_doc and entering datadata (Dictstr, str) The vars and their value. title (str) The title of the new Google Doc.
generate_signnow_docNoneUpdates the Google Doc to replace signature/initial tags with lines, upload PDF to Sign Now and update it to add signature/initial areas. Sets the signnow_doc with the new Sign Now Document
invite_signersDictSend Sign Now invites to the specified emails. Returns a dict for email:user_id mapping.invites (ListSignNowInvite)
downloadbytesDownloads the instance of signnow_doc in PDF format (bytes)
get_previewbytesDownloads the instance of google_doc in PDF format (bytes)

Class SignNowInvite

This class represents an invitation for a Sign Now document.

from documents.services.signnow.document import SignNowInvite

Constructor args

nametyperequireddescription
emailstrYesThe email address of the signatory.
rolestrYesThe signatory role in the Sign Now Document.
orderintNoThe order the signatory must sign the file. E.g. Signatory 1 must sign before Signatory 2. Default to 1.

Properties

nametypedescription
emailstrThe email address of the signatory.
rolestrThe signatory role in the Sign Now Document.
orderintThe order the signatory must sign the file. E.g. Signatory 1 must sign before Signatory 2. Default to 1.

Class GoogleDoc

This class represents a Google Doc file.

from documents.services.google.doc import GoogleDoc

Constructor args

nametyperequireddescription
document_idstrYesThe file id of the Google Doc.

Properties

nametypedescription
documentjsonThe JSON of the whole Google Doc.
batch_update_commandsListThe batch update commands awaiting to be executed.

Methods

namereturn typedescriptionargs
get_idstrReturns the file/document id of the Google Doc
get_titlestrReturns the title of the document (filename)
download_pdfBytesIOConverts the Google Doc in PDF format and downloads it
copyGoogleDocCopy the Google Doc in the same foldertitle (str) The title of the copy
moveNoneMoves the Google Doc in the specified folderfolder_id (str) The folder to move the Google Doc into
shareNoneShares the Google Doc to the specified users with the writer rolerecipients (Liststr) The emails of the users to share the Google Doc with
lockNoneUpdates the Google Doc to be read-only
unlockNoneUpdates the Google Doc to disable the read-only mode
deleteNoneDeletes the Google Doc
get_missing_varsListstrCompares the required variables in the Google Doc and the given data to return the missing variables in the data in order to complete the documentdata (Dictstr, str) var_name:value mapping
is_data_valid_for_varsboolCompares the required variables in the Google Doc and the given data to return if the data is sufficient or notdata (Dictstr, str) var_name:value mapping

Module documents.services.signnow.auth

Function verify_access_token

Verifies that the given access token is valid for your account. This is useful for webhooks, to verify that the request is legitimate (webhook callbacks contain an access_token).

args

nametyperequireddescription
tokenstrYesThe access token to verify.

Module documents.services.signnow.webhook

Function create_doc_completion_webhook

Creates an event subcription for a document completion (when all parties completed their signature). The webhook will call the URL given in the SIGNNOW_API_DOC_COMPLETION_CALLBACK_URL env var when the event is triggered.

args

nametyperequireddescription
document_idstrYesThe Document ID to link the subcription to.

Function create_doc_opening_webhook

Creates an event subcription for a document being opened. The webhook will call the URL given in the SIGNNOW_API_DOC_OPEN_CALLBACK_URL env var when the event is triggered.

args

nametyperequireddescription
document_idstrYesThe Document ID to link the subcription to.

Function create_doc_update_webhook

Creates an event subcription for a document being updated (including an user signing the doc). The webhook will call the URL given in the SIGNNOW_API_DOC_UPDATE_CALLBACK_URL env var when the event is triggered.

args

nametyperequireddescription
document_idstrYesThe Document ID to link the subcription to.

Function delete_webhook

Removes a webhook from your Sign Now account. This can be useful when the event subscription is no longer needed or is no longer possible.

args

nametyperequireddescription
event_subscription_idstrYesThe ID given of the response of the webhook's creation.

Function list_webhooks

Lists all the webhooks of your Sign Now account.

Module documents.services.google.drive

Function copy_file

Duplicate the specified file. The copy will be in the same folder as the original.

args

nametyperequireddescription
file_idstrYesThe id of the file to copy.
titlestrYesThe file name of the copy.

Function lock_file

Updates the specified file to be read-only.

args

nametyperequireddescription
file_idstrYesThe id of the file to be read-only.

Function unlock_file

Updates the specified file to disable the Read-Only mode.

args

nametyperequireddescription
file_idstrYesThe id of the file to disable the Read-Only.

Function delete_file

Deletes the specified file.

args

nametyperequireddescription
file_idstrYesThe id of the file to be deleted.

Function move_file

Moves the specified file into the specified folder.

args

nametyperequireddescription
file_idstrYesThe id of the file to move.
folder_idstrYesThe id of the folder to move the file into.

Function create_folder

Creates a new folder inside the given folder.

args

nametyperequireddescription
file_idstrYesThe id of the folder to create the new folder into.

Function share_file

Gives the specified role to the specified users.

args

nametyperequireddescription
file_idstrYesThe id of the file to give permissions to
recipientsListstrYesThe email of the users to give the role to
rolestrYesThe role to give the users. E.g.: writer

Function upload_pdf

Upload a PDF file with the given name to the specified folder.

args

nametyperequireddescription
databytesYesThe bytes of the file PDF.
namestrYesThe name of the file that will be in Google Drive.
folder_idstrYesThe id of the folder. Your service account must be allowed to write into it.

Function download_pdf

Downloads the specified file in PDF format. Returns the bytes.

args

nametyperequireddescription
file_idstrYesThe id of the file to download in PDF. Can be a Google Doc.
1.0.0

1 year ago