# Add a websocket client to Django (not a server)

**URL:** <https://forum.djangoproject.com/t/add-a-websocket-client-to-django-not-a-server/2916>\
**Category:** Using Django\
**Created:** [June 11, 2020, 7:14am UTC](https://forum.djangoproject.com/t/add-a-websocket-client-to-django-not-a-server/2916 "2020-06-11T07:14:07Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![adamchainz](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/adamchainz/32/26_2.png) [@adamchainz](https://forum.djangoproject.com/u/adamchainz)\
**Post date:** [June 11, 2020, 9:15am UTC](https://forum.djangoproject.com/t/add-a-websocket-client-to-django-not-a-server/2916/2 "2020-06-11T09:15:47Z")

</div>

An ASGI deployment doesn’t help you here indeed. It’s a definition for being a websocket server, not a client.

I’d write a management command that uses `asyncio.run` in its `handle()` to connect to the websocket. The [websockets library](https://pypi.org/project/websockets/) may be of use.

ORM operations to save data to your DB should be done in a sync function wrapped with `sync_to_async`, and you’ll need to take care that you close database connections appropriately.

---

_[View the full topic](https://forum.djangoproject.com/t/add-a-websocket-client-to-django-not-a-server/2916)._
