Skip to main content

Brings async, event-driven capabilities to Django.

Project description

rest_framework_channels

The enhanced modules for REST WebSockets using django channels.

Installation

pip install rest_framework_channels

Introduction

rest_framework_channels is the enhanced modules for REST WebSockets using django channels.

You can use serializers and queryset in rest_framework in rest_framework_channels. Also, we are ready for similar permissions and generics too.

Example

We use the below model and serializer as example.

class TestModel(models.Model):
    """Simple model to test with."""

    title = models.CharField(max_length=255)
    content = models.CharField(max_length=1024)

class TestSerializer(ModelSerializer):
    class Meta:
        model = TestModel
        fields = '__all__'
class ChildActionHandler(generics.RetrieveAPIActionHandler):
    serializer_class = TestSerializer
    queryset = TestModel.objects.all()

class ParentConsumer(AsyncAPIConsumer):

    routepatterns = [
        re_path(
            r'test_child_route/(?P<pk>[-\w]+)/$',
            ChildActionHandler.as_aaah(),
        ),
    ]

When you send the below json after establishing the connection,

{
    'action': 'retrieve', # Similar with GET method of HTTP request
    'route': 'test_child_route/1/',
}

you will get the below response. This mechanism is very similar with original rest_framework!

{
    'errors': [],
    'data': {
        'id': 1,
        'title': 'title',
        'content': 'content'
    },
    'action': 'retrieve',
    'route': 'test_child_route/1/',
    'status': 200,
}

Details

For more details, see docs.

Development

code

pip install -e .
pip install twine

documentation

cd sphinx
pip install -r requirements.txt
  • generate rst files and html files
cd sphinx
bash build.sh

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

rest_framework_channels-0.0.1.tar.gz (16.6 kB view details)

Uploaded Source

Built Distribution

rest_framework_channels-0.0.1-py3-none-any.whl (27.4 kB view details)

Uploaded Python 3

File details

Details for the file rest_framework_channels-0.0.1.tar.gz.

File metadata

File hashes

Hashes for rest_framework_channels-0.0.1.tar.gz
Algorithm Hash digest
SHA256 ea5bebbe2bafde466d2a331cb501d55b04936d0f3cf87a20998e5cfa32e6df97
MD5 c1ea9207cd6caaf45ccd871f62873f58
BLAKE2b-256 4761c190d409783d53b243934cb5a59a3509474f204da9a07d7e9949314f029f

See more details on using hashes here.

File details

Details for the file rest_framework_channels-0.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for rest_framework_channels-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 9d2e9aaf48c3b3bc4a366a6b63be0c71943f0fcf7fe830d9619301a24913b04b
MD5 41509e1ca2da6017f6c0b76ab25bbdbb
BLAKE2b-256 302b8bf0f2d377b217c283a152560c9677ee0c4fa373e9bba55fe67eeeac78a8

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page