centrifugal / centrifugal/centrifuge-python

Support orjson library for JSON parsing

Open
#39 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
61
Forks
19
Avg merge
7h 26m
Merged PRs (30d)
12

Description

It would be great if we could use a third-party JSON library with `centrifuge`.
Currently, we have to rely on hacks like this:

```python
import orjson
import centrifuge.codecs
from centrifuge import Client

class OrjsonWrapper:
"""Wrapper around `orjson` to provide json-compatible interface."""

@staticmethod
def dumps(obj):
return orjson.dumps(obj).decode("utf-8")

@staticmethod
def loads(obj):
return orjson.loads(obj if isinstance(obj, bytes) else obj.encode("utf-8"))

client = Client("wss://ws.example.com")

# Monkey-patching the `json` module in
# `centrifuge.codecs` to be replaced with `orjson`
centrifuge.codecs.json = OrjsonWrapper()
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.