/python-mcs-sdk

python-sdk for multichain storage service

Primary LanguagePythonMIT LicenseMIT

python-mcs-sdk

Made by FilSwan Chat on discord

Table of Contents

A python software development kit for the Multi-Chain Storage (MCS) https://www.multichain.storage/ service. It provides a convenient interface for working with the MCS API. This SDK has the following functionalities:


  • POST Upload file to Filswan IPFS gateway
  • GET List of files uploaded
  • GET Files by cid
  • GET Status from filecoin
  • CONTRACT Make payment to swan filecoin storage gateway
  • CONTRACT Mint asset as NFT

  • POST Create a bucket
  • POST Create a folder
  • POST Upload File to the bucket
  • POST Rename bucket
  • GET Delete bucket
  • GET Bucket List
  • GET File List
  • GET File information
  • GET Delete File

  • Prerequisites

    • web3 - web3 python package to process contract
    1. Method 1. Pip install (Recommended):

      Install python SDK using pip https://pypi.org/project/python-mcs-sdk/

      pip install python-mcs-sdk
      
    2. Method 2. Build from source

      Install python SDK from GitHub (checkout to the main branch for main net support) and install requirements using pip:

      git clone https://github.com/filswan/python-mcs-sdk.git
      git checkout main
      pip install -r requirements.txt
      

👨‍💻 Examples


Here is the demo to get you started; you can get more information in the SDK documentation.

  1. Set Up Wallet Information

    1. Create a .env file that includes the following content.

      api_key="<API_KEY>"
      access_token="<ACCESS_TOKEN>"
      
      ##If you do not use the onchain function, you do not need to configure the following
      private_key="<PRIVATE_KEY>"
      rpc_endpoint="<RPC_ENDPOINT>"
      
      1. The "rpc_endpoint" is the one mentioned above
      2. "Private_key" will be obtained from the wallet
      3. The "api_key" and "access_token" can be generated from the Setting page in the multichain.storage page

      b. Install dotenv

      pip install python-dotenv

  2. Login to MCS

     from mcs import APIClient
     if __name__ == '__main__':
         api_key="<API_KEY>"
         access_token="<ACCESS_TOKEN>"
         mcs_api = APIClient(api_key, access_token)

    For Onchain Storage


    • Init

      from mcs import OnchainAPI
      onchain = OnchainAPI(mcs_api)
    • Upload File to Onchain storage

      print(onchain.upload_file('<File Path>'))

    For Bucket Storage


    • Init

      from mcs import BucketAPI
      bucket = BucketAPI(mcs_api)
    • Create a bucket

      print(bucket.create_bucket('<bucket name>'))
    • Upload a file to the bucket

      print(bucket.upload_to_bucket('<bucket_id>', '<file_path>' ,prefix=''))

      The prefix field defines the file-folder relationship, leaving it blank if the file exists directly in the Bucket or the folder name if the file exists in a folder that already exists in the Bucket.

      You have to create a bucket before you upload a file.

      Note that if you upload a file with the prefix field defined in a folder that has not yet been created, you will not be able to see the file until you create a folder with the same name.

For more examples, please see the SDK documentation.

Contributing

Feel free to join in and discuss. Suggestions are welcome! Open an issue or Join the Discord!

Sponsors

Filecoin Foundation sponsors this project

Flink SDK - A data provider offers Chainlink Oracle service for Filecoin Network