We can set any config parameter (a) via an envvar, or (b) via a config file. Envvar values override config file values.
An Ocean
instance will hold a Config
instance that holds various config parameters. These parameters need to get set. This is set based on what's input to Ocean
constructor:
- dict input:
Ocean({'network':..})
- Config object input:
Ocean(Config('config.ini'))
- no input, so it uses OCEAN_CONFIG_FILE envvar
Here are examples.
First, in console:
export OCEAN_NETWORK_URL=https://rinkeby.infura.io/v3/<your Infura project id>
export METADATA_CACHE_URI=https://aquarius.rinkeby.oceanprotocol.com
export PROVIDER_URL=https://provider.rinkeby.oceanprotocol.com
Then, do the following in Python. The Ocean
constructor takes a dict
, which in turn is set by envvars.
import os
from ocean_lib.ocean.ocean import Ocean
d = {
'network' : os.getenv('OCEAN_NETWORK_URL'),
'metadataCacheUri' : os.getenv('METADATA_CACHE_URI'),
'providerUri' : os.getenv('PROVIDER_URL'),
}
ocean = Ocean(d)
For legacy support, you can also use metadataStoreUri
instead of metadataCacheUri
.
Recall that parameters set by envvars override config file values. So, to use a config value in a file, we must remove its envvar.
Here's how. In the console:
unset OCEAN_NETWORK_URL METADATA_CACHE_URI AQUARIUS_URL PROVIDER_URL
First, in your working directory, create config.ini
file and fill as follows:
[eth-network]
network = https://rinkeby.infura.io/v3/<your infura project id>
[resources]
metadata_cache_uri = https://aquarius.rinkeby.oceanprotocol.com
provider.url = https://provider.rinkeby.oceanprotocol.com
Then, in Python:
from ocean_lib.config import Config
from ocean_lib.ocean.ocean import Ocean
c = Config('config.ini')
ocean = Ocean(c)
We'll use the config.ini
file created from the previous example.
Then, set an envvar for the config file. In the console:
export OCEAN_CONFIG_FILE=config.ini
Then, in Python:
import os
from ocean_lib.config import Config
from ocean_lib.ocean.ocean import Ocean
c = Config(os.getenv("OCEAN_CONFIG_FILE"))
ocean = Ocean(c)
The file config.py lists all the config parameters.
For the most precise description of config parameter logic, see the Ocean() constructor implementation.