centrifugal / centrifugal/centrifuge-python
Support orjson library for JSON parsing
- 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.