Skip to content

Telefonica/latch-sdk-python

 
 

Repository files navigation

LATCH PYTHON SDK

Prerequisites

  • Python.

  • Read API documentation (https://latch.tu.com/www/developers/doc_api).

  • To get the "Application ID" and "Secret", (fundamental values for integrating Latch in any application), it’s necessary to register a developer account in Latch's website: https://latch.tu.com. On the upper right side, click on "Developer area"

Using the SDK

  • Install "latch-sdk-telefonica"

    pip install latch-sdk-telefonica
  • Import "LatchSDK" class.

    from latch_sdk.syncio  import LatchSDK
  • Import one of Latch core classes (read the docs).

    from latch_sdk.syncio.pure  import Latch
  • Create a Latch object with the "Application ID" and "Secret" previously obtained.

    api = LatchSDK(Latch("APP_ID_HERE", "SECRET_KEY_HERE"))
  • Call to Latch Server. Pairing will return an account id that you should store for future api calls

    account_id = api.account_pair("PAIRING_CODE_HERE")
    status = api.account_status(account_id)
    assert api.account_unpair(account_id) is True

Using the SDK for web3 contracts

For using the Python SDK within an Web3 service, you must complain with the following:

  • It is necessary to have a developer subscription that allows you to create web3 apps.
  • You need metamask extension for Google Chrome Download metamask
  • You need a wallet to operate on Polygon. You can easily create one through Metamask.

Creation of a WEB3 Latch app

Once you have your developer Latch account created, you must logging in the website.

We add a new method to pair the web3 applications, now we have two new parameters. The two additional parameters are:

  • WEB3ACCOUNT: The Ethereum-based address account for the user that wants to pair the service.
  • WEB3SIGNATURE: A proof-of-ownership signature of a constant, in order to verify that the user owns the private key of the wallet. You can use https://etherscan.io/verifiedSignatures# to sign the following message:
    • MESSAGE TO SIGN : "Latch-Web3"
  • Call to Latch Server for pairing as usual, but with the newly methods:
    api = LatchSDK(Latch("APP_ID_HERE", "SECRET_KEY_HERE"))
    # PAIR
    account_id = api.account_pair(pairing_code, WEB3ACCOUNT, WEB3SIGNATURE)