The Vect SDK provides a safe and easy way to access the parameters you manage in app.vect.io, allowing you to read parameters and react to changes in a fault-tolerant way.
Install Node.js via a package manager. ****Used only for the injector’s runtime at process startup. After startup, your process runs natively.
Install the Vect SDK Daemon
(PKG_CREDS=<pkg-creds> && \\
VERSION=0.0.13 && \\
npm remove @vect-io/grpc-vect-sdk && npm install -g <https://[email protected]/artifactory/prod-v2022-1-npm-local/%40vect-io/grpc-vect-sdk/-/%40vect-io/grpc-vect-sdk-$VERSION.tgz> )
<aside>
💡 npm can be replaced with yarn . For pnpm, use npm install -g
</aside>
Install the Vect SDK Python Adapter. Use the package credentials when prompted.
pip install vect-sdk --upgrade --force-reinstall -i <https://vect.jfrog.io/artifactory/api/pypi/prod-v2022-1-pypi-local/simple> --extra-index-url <https://pypi.org/simple>
<aside> 💡 If you want to store the repository credentials in your keyring, make sure to globally install and configure it first. Notice this will not be persisted in docker environments
</aside>
Or add Vect's PyPi as a custom package index.
Start the SDK daemon
npm exec init-vect-sdk-daemon
<aside>
💡 npm can be replaced with yarn
</aside>
Initialize your Vect repository client:
from vect_sdk import VectRepository, ApiKey
import os
vect_repo = VectRepository(
repo_path='acme-com/acme-com-2022v1',
api_key_struct=ApiKey(api_key_name='acme-com-2022v1', api_key=os.getenv('VECT_API_KEY')),
)
In order to subscribe to a file, use vect_repo.watch_file to keep the parameters up to date and cached for fault tolerance.
To access the current state of a file:
watched_file = vect_repo.watch_file('foo/bar/baz.json')
print(f'foo/bar/baz.json: {watched_file.get_latest()}')
get_latest returns the latest update of watch_file instantly without a network request after the first run.
The SDK also provides local caching, continuous updates, fault tolerance, and zero latency. VectRepository will always cache responses in memory, falling back to the last response on failure.
get_latest_baz = vectRepo.watch_file('foo/bar/baz.json')
# ...
baz = get_latest_baz() # instant after first run