Django channels endpoints
Project description
Django channels endpoints
This package provides endpoints as functions for django channels package.
Installation
pip install channels-endpoints
Usage
In your django app create dce.py file:
from channels_endpoints.main import endpoint, Response
from django.contrib.auth.models import User
from django.core import serializers
from .permissions import UsersPermissions
from asgiref.sync import sync_to_async
users_logger = logging.getLogger('users')
@endpoint(logger=users_logger, permissions=[UsersPermissions], timeout=42)
async def get_users(request):
print(request.data)
def _get():
return serializers.serialize('python', User.objects.all(), fields=('username', 'id'))
await request.consumer.send(text_data=Response(None, f'hello', consumers=['SomeConsumer']))
return Response(
request,
await sync_to_async(_get)()
)
Python client:
from channels_endpoints.client import Dce, DceException, consumer
@consumer
async def SomeConsumer(response):
print(f'SomeConsumer: {response["data"]}')
dce = Dce('http://127.0.0.1:8000/ws/')
try:
data = await dce.request('myapp.get_users', {'some': 'data'})
except DceException as e:
print(e.__repr__())
dce.close()
Javascript client:
import {dce, consumer} from "channels_endpoints"
consumer('SomeConsumer', (response) => {
console.log('SomeConsumer: ', response.data)
})
dce('myapp.get_users', {some: "data"}).then(
response => {
console.log('users:', response)
}
)
see js client package https://www.npmjs.com/package/channels_endpoints
Examples
For complete usage examples see example chat
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file channels_endpoints-1.0.3.tar.gz.
File metadata
- Download URL: channels_endpoints-1.0.3.tar.gz
- Upload date:
- Size: 9.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4f8898177f3f9c2001c97b2d98f6ccbb846b242c7f01535988880415dee7b4c7
|
|
| MD5 |
f7fa3e754c4a2e86a68443e0154c0a42
|
|
| BLAKE2b-256 |
237029397e96a28812ec0be5ca3e194d47c6fb2059d00b12c7f39d38a4296667
|
File details
Details for the file channels_endpoints-1.0.3-py3-none-any.whl.
File metadata
- Download URL: channels_endpoints-1.0.3-py3-none-any.whl
- Upload date:
- Size: 10.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a9989fd05d7bf43a52bdf7b4bcaa5ba1af9278e5493d4d07d2512ecfd58b03f0
|
|
| MD5 |
25495d3bcab8f3126c5717c36d1df2c9
|
|
| BLAKE2b-256 |
3d7e1bdaac88daa77335c1affbf016643a81ac71b357d5ab8f9459c45688796a
|