django-river-ml package
Submodules
django_river_ml.announce module
django_river_ml.apps module
django_river_ml.auth module
- django_river_ml.auth.generate_jwt(username)[source]
Given a username generate a jwt token to return to the user with a default expiration of 10 minutes.
username (str) : the user’s username to add under “sub”
- django_river_ml.auth.get_challenge(request)[source]
Given an unauthenticated request, return a challenge in the Www-Authenticate header
request (requests.Request): the Request object to inspect
- django_river_ml.auth.get_token(request)[source]
The same as validate_token, but return the token object to check the associated user.
request (requests.Request) : the Request object to inspect
- django_river_ml.auth.get_user(request)[source]
Given a request, read the Authorization header to get the base64 encoded username and token (password) which is a basic auth. If we return the user object, the user is successfully authenticated. Otherwise, return None. and the calling function should return Forbidden status.
request (requests.Request) : the Request object to inspect
django_river_ml.client module
- class django_river_ml.client.DjangoClient[source]
Bases:
object
The Django client provides the main interaction between the storage and an internal user. It directly wraps the database, and is used by RiverClient to return responses to the API. If you need to interact with your models from inside of a Django application, use this class.
- finish_learn(event, prediction, features, ground_truth, model_name, identifier=None, **kwargs)[source]
Finish a learning event. This can either be a prediction ‘predict’ event that was done on the server, or a ‘label’ event that retrieved a previous prediction and then updated metrics or the model.
- label(label, identifier, model_name)[source]
Given a previous prediction (we can get with an identifier) add a label.
- learn(model_name, ground_truth=None, prediction=None, features=None, identifier=None, **kwargs)[source]
A learning event takes a learning schema
- class django_river_ml.client.RiverClient[source]
Bases:
object
A river client includes shared functions for interacting with storage. This implementation was chosen so it can easily be plugged into another kind of server without needing to deal with the server-specific requests.
- label(label, identifier, model_name)[source]
Given a previous prediction (we can get with an identifier) add a label.
- learn(model_name, ground_truth=None, prediction=None, features=None, identifier=None, **kwargs)[source]
A learning event takes a learning schema
django_river_ml.exceptions module
- exception django_river_ml.exceptions.FlavorNotSet(*args, **kwargs)[source]
Bases:
InvalidUsage
django_river_ml.flavors module
- class django_river_ml.flavors.BinaryFlavor[source]
Bases:
Flavor
- property name
- property pred_funcs
Listing of prediction functions to try (in that order)
- class django_river_ml.flavors.ClusterFlavor[source]
Bases:
Flavor
- property name
- property pred_funcs
Listing of prediction functions to try (in that order)
- class django_river_ml.flavors.CremeFlavor[source]
Bases:
Flavor
- property learn_func
Learn function consistent for all models in river, creme is fit_one
- property name
- property pred_funcs
Listing of prediction functions to try (in that order)
- class django_river_ml.flavors.CustomFlavor[source]
Bases:
Flavor
A custom flavor aims to support a user custom model.
- property name
- property pred_funcs
Listing of prediction functions to try (in that order)
- class django_river_ml.flavors.Flavor[source]
Bases:
ABC
- abstract check_model(model: Any) Tuple[bool, str] [source]
Checks whether or not a model works for a flavor.
- abstract default_metrics() List[Metric] [source]
Default metrics to record globally as well as for each model.
- property learn_func
Learn function consistent for all models in river, creme is fit_one
- abstract property name
- abstract property pred_funcs: str
Listing of prediction functions to try (in that order)
- class django_river_ml.flavors.MultiClassFlavor[source]
Bases:
Flavor
- property name
- property pred_funcs
Listing of prediction functions to try (in that order)
- class django_river_ml.flavors.NeighborFlavor[source]
Bases:
Flavor
- property name
- property pred_funcs
Listing of prediction functions to try (in that order)
django_river_ml.middleware module
django_river_ml.model module
django_river_ml.namer module
django_river_ml.settings module
django_river_ml.signals module
- django_river_ml.signals.create_auth_token(sender, instance=None, created=False, **kwargs)[source]
Create a token for the user when the user is created
Assign user a token
Create a token instance for all newly created User instances. We only run on user creation to avoid having to check for existence on each call to User.save. We also check if one is already created in case another app or the main user application is running the same function.
django_river_ml.storage module
- class django_river_ml.storage.RedisBackend(host, port, db)[source]
Bases:
StorageBackend
Redis is the suggest backend for a more production database.
- class django_river_ml.storage.ShelveBackend(filename, flag='c', protocol=None, writeback=False)[source]
Bases:
DbfilenameShelf
,StorageBackend
Storage backend based on the shelve module from the standard library.
This should mainly be used for development and testing, but not production.
- class django_river_ml.storage.StorageBackend[source]
Bases:
ABC
Abstract storage backend.
This interface defines a set of methods to implement in order for a database to be used as a storage backend. This allows using different databases in a homogeneous manner by proving a single interface. Since online-ml models are largely defined by Python dictionaries, we use key value store databases like redis.
- django_river_ml.storage.add_model(model: Estimator, flavor: str, name: str | None = None) str [source]
- django_river_ml.storage.drop_db()[source]
This function’s responsability is to wipe out a database.
This could be implement within each StorageBackend, it’s just a bit more akward because at this point the database connection is not stored in the app anymore.
- django_river_ml.storage.get_db() StorageBackend [source]
Get the database, an attribute of settings.
django_river_ml.urls module
django_river_ml.utils module
- django_river_ml.utils.format_sse(data: str, event=None) str [source]
>>> format_sse(data=json.dumps({'abc': 123}), event='Jackson 5') 'event: Jackson 5\ndata: {"abc": 123}\n\n'