Tutorial on how to use the Nevermined Payments Protocol in Python
The objective of this library is to make possible the integration of Nevermined payments in the Python code ecosystem. This library provides a set of functions to interact with the Nevermined network, including the ability to register subscriptions and subscribe to web services and get the JWT access token to call them.
To have full details about how to use the Payments Library, please visit the documentation section
Installation
Install the nevermined payments library using pip:
pip install payments-py
Initialize the payments library
In a previous tutorial we showed what is a Nvm Api Key and how to obtain it.
To initialize the payments library, you need to provide the following parameters:
- Nvm Api key: It's a string that identifies the session key of the account abstraction and some extra data as the marketplace auth token. It works similar to a jwt but for blockchain accounts. You can find more in zeroDev docs.
- Environment: It's an enum that represents the environment where the library will interact with the Nevermined network. It can be
Environment.appTesting
orEnvironment.appArbitrum
. - App id: It's a string that represents the app id. Currently is optional.
- Version: It's a string that represents the version of the app. Currently is optional.
from nevermined_payments import Payments
payments = Payments(nvm_api_key=nvm_api_key, environment=Environment.appTesting, app_id="your_app_id", version="1.0.0")
Using payments library
Once you have initialized the payments library, you can use the methods as following:
response = payment.create_subscription(name="test-py", description="test", price=1000000, token_address="0x75faf114eafb1BDbe2F0316DF893fd58CE46AA4d", amount_of_credits=100, duration=30, tags=["test"])
In the following link you can find the complete documentation of the library: payments-py.
Example
Here you can find an example of how to use the payments library and try yourself: