- Setup
1.1 Clone the Repository First, clone the ocean.py repository:
git clone https://github.com/oceanprotocol/ocean.py.git cd ocean.py 1.2 Install the Package Install the ocean.py package:
pip install ocean-lib 2. Remote Setup Follow the instructions in the setup-remote.md to set up a remote environment. This involves:
2.1 Setting up Environment Variables You'll need to set up several environment variables, including:
INFURA_PROJECT_ID: Your Infura project ID. OCEAN_NETWORK_URL: The URL of the Ocean network you're connecting to. FACTORY_DEPLOY_BLOCK: The block number when the factory was deployed. METADATA_CONTRACT_BLOCK: The block number when the metadata contract was deployed.
2.2 Using the Barge The Barge is a tool provided by Ocean Protocol to run a local Ocean network. If you're using the Barge, you'll need to set up additional environment variables.
- Consume Flow 3.1 Initialize Ocean Before you can consume data, you need to initialize the Ocean instance:
from ocean_lib.ocean.ocean import Ocean from ocean_lib.config import Config
config = Config('path_to_config.ini') ocean = Ocean(config) 3.2 Search for Data Search for datasets on the Ocean marketplace:
search_results = ocean.assets.search('your_search_query') 3.3 Select a Dataset From the search results, select a dataset you want to consume:
dataset = search_results[0] 3.4 Consume the Data To consume the data, you'll need to purchase it first:
order_requirements = ocean.assets.order(dataset.did, 'access') service_agreement_id = ocean.assets.pay_for_service(order_requirements, dataset) Once the payment is successful, you can consume the data:
consumer = ocean.assets.download( dataset.did, service_agreement_id, order_requirements, 'path_to_save_data' )
-
Handle Errors and Exceptions Ensure you handle any errors or exceptions that might occur during the consume flow. This includes checking if you have enough Ocean tokens to purchase the data, if the dataset is still available, and if there are any network issues.
-
Cleanup and Shutdown After consuming the data, ensure you close any open connections and clean up any temporary files or resources.