Skip to main content

A realtime messaging server using WebSockets and Redis.

Project description

General

PyPI version Build Status License codecov

Cobra is a realtime messaging server using Python3, WebSockets and Redis Streams. It was presented in great details during RedisConf 2019.

Cobra has been used in production receiving heavy traffic for about a year. Since it was written in Python it was named after a snake as an hommage to a great programming language.

News

Cobra is actively being developed, check out the changelog to know what's cooking.

Installation

With pip

pip install cobras

With docker

docker pull bsergean/cobra

For development

git clone <url>
cd cobra
python3 -m venv venv
source venv/bin/activate
make dev
make test

Usage

Cobra server and test clients

$ cobra
Usage: cobra [OPTIONS] COMMAND [ARGS]...

  Cobra is a realtime messaging server using Python3, WebSockets and Redis
  PubSub.

Options:
  --version  Show the version and exit.
  --help     Show this message and exit.

Commands:
  admin            Run admin commands.
  health           Health check
  init             Setup cobra
  monitor          Monitor cobra
  publish          Publish to a channel
  run              Run the cobra server
  redis_subscribe  Subscribe to a channel (with redis)
  subscribe        Subscribe to a channel
  secret           Generate secrets used for authentication...

To run the server use cobra run. You can run a health-check against the server with cobra health.

cobra health --url 'ws://cobra.jeanserge.com/v2?appkey=_health' --secret A5a3BdEfbc6Df5AAFFcadE7F9Dd7F17E --role health

bavarde

bavarde is a chat client that runs against the public cobra server. Bring up 2 terminals, runs the 2 commands below and start typing.

$ bavarde client
...
$ bavarde client --username bob
...

Setup

To run in production you will need a redis (version > 5) instance. Here are environment variables that you will likely want to tweak, to connect to 2 redis instances (for scalabity), and to bind on 0.0.0.0 so that the internet can see your instance.

- name: COBRA_HOST
  value: 0.0.0.0
- name: COBRA_REDIS_URLS
  value: redis://redis1;redis://redis2

Thank you

There would be no cobra without some other amazing open-source projects and tech. Here are 3 very remarkable ones.

  • Python (and asyncio, one of the killer python3 feature !)
  • Redis, the swiss army knife of the internet which provide a very scalable publish/subscribe feature to dispatch messages while retaining them and allowing lookups of old messages (see [Redis Streams] (https://redis.io/topics/streams-intro).
  • The python websockets library, very elegantly implementing the WebSockets protocol.

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cobras-1.4.5.tar.gz (34.4 kB view details)

Uploaded Source

File details

Details for the file cobras-1.4.5.tar.gz.

File metadata

  • Download URL: cobras-1.4.5.tar.gz
  • Upload date:
  • Size: 34.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.2

File hashes

Hashes for cobras-1.4.5.tar.gz
Algorithm Hash digest
SHA256 9757cd2e90a787a620394031deb267c6c7a508c23c0afe301aa15a7b5c469b35
MD5 e8100831c660d2ac2201641fff354d7a
BLAKE2b-256 a88f583f6d002c76784eeade92d8d887e56b5c0a03b2939e30448eb63c66c6b8

See more details on using hashes here.

Supported by

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