All Projects → machinezone → cobra

machinezone / cobra

Licence: BSD-3-Clause License
Cobra is a realtime messaging server using Python3, WebSockets and Redis

Programming Languages

python
139335 projects - #7 most used programming language
C++
36643 projects - #6 most used programming language
javascript
184084 projects - #8 most used programming language
shell
77523 projects
C#
18002 projects
CMake
9771 projects

Projects that are alternatives of or similar to cobra

typesocket
🌐 TypeScript WebSockets library.
Stars: ✭ 24 (-20%)
Mutual labels:  websockets
bong-bong
Open public chat service built for the web.
Stars: ✭ 17 (-43.33%)
Mutual labels:  websockets
Study-Room
Connect and study together with friends over text and voice channels, over a click of a button. Web application for chat and audio streaming.
Stars: ✭ 21 (-30%)
Mutual labels:  websockets
React-Help-Desk
Help desk style live chat with administrative control panel in React, Node.js and Websockets
Stars: ✭ 29 (-3.33%)
Mutual labels:  websockets
pushest
Bidirectional Pusher client in Elixir
Stars: ✭ 33 (+10%)
Mutual labels:  websockets
node-rtsp-stream-es6
Stream any RTSP stream and output to websocket for consumption by jsmpeg. 📹
Stars: ✭ 91 (+203.33%)
Mutual labels:  websockets
apollo-chat-graphql-server
Apollo Chat is a Chat Service build on GraphQL Apollo with Subscriptions
Stars: ✭ 13 (-56.67%)
Mutual labels:  websockets
crypto-websocket-extensions
🧰 Unified and optimized data structures across cryptocurrency exchanges
Stars: ✭ 31 (+3.33%)
Mutual labels:  websockets
canvas
Draw on an HTML 2D canvas in a web browser from a server program using WebSockets.
Stars: ✭ 71 (+136.67%)
Mutual labels:  websockets
text
An experiment with WebSockets and the human condition.
Stars: ✭ 51 (+70%)
Mutual labels:  websockets
realtime-chat-go-react
An example of a Real-Time Chat Application built using React.js and Go!
Stars: ✭ 61 (+103.33%)
Mutual labels:  websockets
megaphone
Hear ye, hear ye 📣
Stars: ✭ 15 (-50%)
Mutual labels:  websockets
aurelius
A complete solution for previewing markdown written in Rust.
Stars: ✭ 62 (+106.67%)
Mutual labels:  websockets
viper
Real-time tracking and analytics using Node.js and Socket.IO
Stars: ✭ 12 (-60%)
Mutual labels:  websockets
pzgps
Read GPS data from a PiZero in a single page web app via a WebSocket
Stars: ✭ 12 (-60%)
Mutual labels:  websockets
dataviewer-example
📊 Usage examples of dataviewer - https://github.com/jasrodis/dataviewer
Stars: ✭ 15 (-50%)
Mutual labels:  websockets
browserglue
Exposes multiple OSC connections to the browser through WebSockets
Stars: ✭ 21 (-30%)
Mutual labels:  websockets
react-admin-nest
React和Ant Design和 Nest.js 和 Mysql 构建的后台通用管理系统。持续更新。
Stars: ✭ 123 (+310%)
Mutual labels:  websockets
node-jsonrpc2
JSON-RPC 2.0 server and client library, with HTTP (with Websocket support) and TCP endpoints
Stars: ✭ 103 (+243.33%)
Mutual labels:  websockets
chatr
Chat app using Azure Web PubSub, Static Web Apps and other Azure services
Stars: ✭ 51 (+70%)
Mutual labels:  websockets

General

PyPI version Build Status PyPI Python Versions License Wheel codecov

Cobra is a realtime messaging server using Python3, WebSockets and Redis Streams. It was presented in great details during RedisConf 2019. Since then we've added history support which let cobra retain messages published to a channel that no-one is subscribed to. This makes it easier to blow up your systems through OOMs and fill your hard drives, but it makes cobra much more useful.

Alt text

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.

There are 4 operations that a client can execute against a cobra server: publish, subscribe, read and write. publish and subscribe are the 2 operations core to a group-chat. read and write are the typical operations that key value stores (such as memcached), or a python dictionnary provide.

  • publish: send data to a channel, which will be broadcasted to anyone subscribed to that channel
  • subscribe: receive events sent to a channel in real time.
  • write: record some data (addressed by a key)
  • read: retrieve data

Interested ? Go read the docs ! If things don't work as expected, please create an issue in github, or even better a pull request if you know how to fix your problem.

News

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

Installation

UNIX one liner

/bin/sh -c "`curl -fsSL https://raw.githubusercontent.com/machinezone/cobra/master/tools/install.sh`"

You can see what the install script is doing first here.

With pip

pip install cobras

With docker

docker pull bsergean/cobra

With docker-compose

Clone this repo first, then:

make docker
docker-compose up

Or as a one-liner:

(cd /tmp && curl -O https://raw.githubusercontent.com/machinezone/cobra/master/docker-compose.yml && echo 'DOCKER_REPO=bsergean\nTAG=latest' > .env && docker-compose up)

For development

git clone <url>
cd cobra
python3 -m venv venv
source venv/bin/activate
make dev    # please also install redis to execute tests
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 --endpoint ws://jeanserge.com --appkey _health --rolesecret A5a3BdEfbc6Df5AAFFcadE7F9Dd7F17E --rolename 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

cobras init needs to be run once to generate an app configuration file, in ~/.cobra.yaml. That file contains all the roles, secrets and apps configured. Clients will use this data to authenticate.

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

# config can be a path to a file
- name: COBRA_APPS_CONFIG_PATH
  value: /path/to/your/cobra.yaml

# config can be a blob of gziped + base64 data (if you do not want to mount volumes)
# Generate it with:
# `gzip -c ~/.cobra.yaml | base64`
- name: COBRA_APPS_CONFIG_CONTENT
  value: BIGBLOGOFDATA

Users

If your company or project is using this library, feel free to open an issue or PR to amend this list.

  • Machine Zone

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 using asyncio.
  • The python aioredis library used to talk to Redis. This redis labs article explains some pitfalls with asyncio and how to get the best performance out of it.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].