Skip to main content

Build Status

SocketIO PostgreSQL PubSub Websocket Server

What Is This?

This is a websocket server that uses PostgreSQL as its message transport system.

If you have an application that already uses postgres, you can easily send and receive asynchronous events via your existing database. Check out the postgres documentation on LISTEN/NOTIFY for more details.

How Do I Use This?

Server

Configuration

First configure a database connection string in DATABASE_URL. You can create a local.cfg:

# local.cfg
SQLALCHEMY_DATABASE_URI = 'postgresql:///mydatabase
DEBUG = True

Or set DATABASE_URL in your environment. If you use Heroku and have a database attached, this will be set already.

Prerequisites

Note: python 3.6 or higher is required. pip install -r requirements.txt

Run

  • Debug server mode: DEBUG=1 python socketio_pg/server.py
  • In gunicorn (production): gunicorn --worker-class eventlet -w 1 socketio_pg.server:app
  • If using Heroku, a Procfile is already set up for you.

Client

On the client side, you simply connect a socket.io client to begin sending and receiving events. There's a simple demo HTML page at socketio_pg/static/test.html that you can access from the dev server at http://localhost:3030/static/test.html.

Why Use This?

If your application already uses PostgreSQL, you can start sending and receiving asynchronous events right away. It makes an excellent transport for messages (keep them small though, under 8000 bytes), and you can simply issue queries to do it. No additional infrastructure needed, besides this websocket server. If you aren't using PostgreSQL, maybe you should be.

One neat trick is to set up triggers that emit NOTIFY queries when rows on certain tables are inserted or updated. This allows messages to be delivered to clients notifying them of updates without any application code at all. Some demos and slides from a talk can be found here.

In Action

socketio_pg in action

How Is This Built?

This server uses the following technologies:

  • Flask - python web microframework
  • psycopg2 - postgresql driver
  • eventlet - lightweight green threading library
  • greenlet - app threads in python
  • socket.io - client and server layer on top of websockets to handle namespacing, reconnection, and basic session management

Metadata

Release files for socketio-pg 0.13

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for socketio-pg 0.13
File Size Uploaded
socketio_pg-0.13.tar.gz 7.7 kB Details

Release files / socketio_pg-0.13.tar.gz

Download URL socketio_pg-0.13.tar.gz
Size 7.7 kB
Tags Source
SHA-256 checksum
How to use checksums
7c6249c453307067cc74f761662fc8653144d3906bc37537da1bf27cd8038549
BLAKE2b-256 checksum
How to use checksums
8d1e57f25325c80c44f35a0cec9f2f31778043fc52b7917caff0aeb003a9cad4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.12.1 pkginfo/1.4.2 requests/2.18.4 setuptools/39.2.0 requests-toolbelt/0.8.0 tqdm/4.23.3 CPython/3.6.4

Release history Release notifications | RSS feed

This release

0.13 This release

1 release file

0.11

1 release file

0.10

1 release file

0.9

1 release file

0.8

1 release file

0.7

1 release file

0.6

1 release file

0.5

1 release file

0.4

1 release file

0.3

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page