DJ StreamIO
Framework for making it easy to post stream updates to (stream.io)[https://getstream.io]
Installation
pip install dj-streamio
Configuration
1. Add streamio to INSTALLED_APPS
2. Configure your models for tracking:
e.g.:
from streamio.mixins import StreamModelMixin
class Todo(models.Model, StreamModelMixin):
collection = 'todos'
feed_name = 'todo'
feed_actor_field = 'owner_id'
feed_once_off_actions = ["create"]
feed_related_mapping = [
# feed_slug, model_field
('user', 'owner_id'),
('todo', 'id'),
]
# a list of object_id prefixes to look for in the `object_ids` field
# e.g.: todo.object_ids = ["foo:1", "bar:2"]
feed_object_ids_mapping = ["foo", "bar"]
enrichment_serializer = 'example_app.models.TodoSerializer'
Notes:
- We add
StreamModelMixinto our model - Add the various meta fields
- Profit
Track actions:
todo = Todo.objects.first()
todo.track_action('create')
todo.track_action('start')
todo.track_action('complete')
Add reaction:
You can add a reaction (e.g.: like, comment, upvote etc) to an activity
Example
todo.add_reaction(
activity_kind, # e.g.: like, comment, status
activity_id,
data,
by=user_id,
target_feeds=["notification:thierry"]
)
notes:
datais the reaction data. e.g.:{"text": "@thierry great post!"}by(optional) will default to the modelsactor_idif none is provided.target_feeds(optional) will default to the modelsfeed_related_mapping.
Stream docs on Reactions: https://getstream.io/docs/python/#reactions_introduction
Add notifications:
todo = Todo.objects.first()
# note: you'll need to setup a webhook to actually handle forwarding!
# https://getstream.io/docs/#realtime-webhooks
# a combination of ways to propagate this notification (all are optional)
forward = {
"sms": ['+27...', '+27...'],
"inapp": ['user:1', 'user:2'], # inapp notification channels
"email: ['jane@soap.com', 'joe@soap.com']
}
todo.add_notification(
verb="..",
notify=[user1.id, user2.id],
message='hello!',
forward = forward
)
Get Feed
todo = Todo.objects.first()
# get feed with all the defaults
todo.get_feed()
# you can set any extra args with kwargs:
# available parameters: https://getstream.io/docs/python/#retrieve
todo.get_feed({"limit": 5, "offset": 5, "enrich": False})
Feed mixin
dj-streamioprovides a mixin that can be used to expose a/stream/endpoint on a DjangoRestFrameworkModelViewSet. This endpoint proxiess the group feed for the underlying model. It also provides an analytics endpoint which gives a breakdown of the last 100 activities at/streamactivity/
Example:
from streamio.viewsets import StreamViewSetMixin
# for older versions of DRF (prior to the @action update) use this mixin
# from streamio.viewsets_legacy import StreamViewSetMixin
...
# then simply mix it into your ViewSet:
class TodoViewSet(StreamViewSetMixin, viewsets.ModelViewSet):
queryset = Todo.objects.all()
serializer_class = TodoSerializer
# /todos/:pk/stream/
# /todos/:pk/streamactivity/
Low level usage
from streamio.streamio import get_client
stream = get_client() # returns a standard logged-in stream.io client
...
Note:
- See also:
StreamObjectandStreamUser
TODOS:
- Provide alternative backends (later)
Metadata
Release files for dj-streamio 0.2.12
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 | |
|---|---|---|---|---|
| dj-streamio-0.2.12.tar.gz | 6.4 kB | Without provenance | Details |
Release files / dj-streamio-0.2.12.tar.gz
| Download URL | dj-streamio-0.2.12.tar.gz |
|---|---|
| Size | 6.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
843b77634325cb5c7e3392a88f2f689d94d81c0b433dc9807c28b9877cc47df4
|
|
BLAKE2b-256 checksum How to use checksums |
c0711f4eeadce9202a92392461279dbab67dd2f7a9c49a66e4ac1f1c41a94e23
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.7.15
|
Security for dj-streamio 0.2.12
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.