River API Client
This is an API client created for django-river-ml that is intended to make it easy to interact with an online ML server providing river models (learning, predicting, etc.). It currently does not provide a terminal or command line client and is intended to be used from Python, but if there is a good use case for a command line set of interactions this can be added.
Quick Start
Given that you have a server running that implements the same space as django-river-ml, you can do the following. Note that if your server requires authentication, you can generate a token and export to:
export RIVER_ML_USER=dinosaur
export RIVER_ML_TOKEN=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
And then do the following example.
from river import datasets
from river import linear_model
from river import preprocessing
from riverapi.main import Client
def main():
# This is the default, just to show how to customize
cli = Client("http://localhost:8000")
# Basic server info (usually no auth required)
cli.info()
# Upload a model
model = preprocessing.StandardScaler() | linear_model.LinearRegression()
# Save the model name for other endpoint interaction
model_name = cli.upload_model(model, "regression")
print("Created model %s" % model_name)
# Train on some data
for x, y in datasets.TrumpApproval().take(100):
cli.learn(model_name, x=x, y=y)
# Get the model (this is a json representation)
model_json = cli.get_model_json(model_name)
model_json
# Saves to model-name>.pkl in pwd unless you provide a second arg, dest
cli.download_model(model_name)
# Make predictions
for x, y in datasets.TrumpApproval().take(10):
res = cli.predict(model_name, x=x)
print(res)
# By default the server will generate an identifier on predict that you can
# later use to label it. Let's do that for the last predict call!
identifier = res['identifier']
# Let's pretend we now have a label Y for the data we didn't before.
# The identifier is going to allow the server to find the features,
# x, and we just need to do:
res = cli.label(label=y, identifier=identifier, model_name=model_name)
print(res)
# Note that model_name is cached too, and we provide it here just
# to ensure the identifier is correctly associated.
# Get stats and metrics for the model
cli.stats(model_name)
cli.metrics(model_name)
# Get all models
print(cli.models())
# Stream events
for event in cli.stream_events():
print(event)
# Stream metrics
for event in cli.stream_metrics():
print(event)
# Delete the model
cli.delete_model(model_name)
if __name__ == "__main__":
main()
Contributors
We use the all-contributors tool to generate a contributors graphic below.
Vanessasaurus 💻 |
License
This code is licensed under the MPL 2.0 LICENSE.
Metadata
Release files for riverapi 0.0.21
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| riverapi-0.0.21.tar.gz | 17.3 kB | Without provenance | Details for riverapi-0.0.21.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| riverapi-0.0.21-py3-none-any.whl | Python 3 | none | any | Details for riverapi-0.0.21-py3-none-any.whl |
Total release size: 34.5 kB
Release files / riverapi-0.0.21.tar.gz
| Download URL | riverapi-0.0.21.tar.gz |
|---|---|
| Size | 17.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0e29b7104c6028db6c3676f45dedc52f32375d3eda94fa8edd466bf7ef9954ff
|
|
BLAKE2b-256 checksum How to use checksums |
9cc7da0a16b47a7a38a32e02738bd147bf3665679dd211776070da8a65e1fbb3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.7.1 importlib_metadata/4.8.2 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.63.0 CPython/3.9.7
|
Release files / riverapi-0.0.21-py3-none-any.whl
| Download URL | riverapi-0.0.21-py3-none-any.whl |
|---|---|
| Size | 17.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
380472a067252f5011a5d616049b64cdc8f46aade64ce7a2f8bca92972de0df9
|
|
BLAKE2b-256 checksum How to use checksums |
4c0b027dcdb3495585017d4dea39be0340d62776e690d923f2763079d9a0f57f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.7.1 importlib_metadata/4.8.2 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.63.0 CPython/3.9.7
|
Security for riverapi 0.0.21
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.