Skip to content

Commit

Permalink
refactor: replace orjson support with msgspec
Browse files Browse the repository at this point in the history
  • Loading branch information
VincentRPS committed Jul 14, 2023
1 parent cada37a commit 0bd0313
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ Optional Packages

* `PyNaCl <https://pypi.org/project/PyNaCl/>`__ (for voice support)
* `aiodns <https://pypi.org/project/aiodns/>`__, `brotlipy <https://pypi.org/project/brotlipy/>`__, `cchardet <https://pypi.org/project/cchardet/>`__ (for aiohttp speedup)
* `orjson <https://pypi.org/project/orjson/>`__ (for json speedup)
* `msgspec <https://pypi.org/project/msgspec/>`__ (for json speedup)

Please note that while installing voice support on Linux, you must install the following packages via your preferred package manager (e.g. ``apt``, ``dnf``, etc) BEFORE running the above commands:

Expand Down
12 changes: 6 additions & 6 deletions discord/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,11 @@
from .errors import HTTPException, InvalidArgument

try:
import orjson
import msgspec
except ModuleNotFoundError:
HAS_ORJSON = False
HAS_MSGSPEC = False
else:
HAS_ORJSON = True
HAS_MSGSPEC = True


__all__ = (
Expand Down Expand Up @@ -662,12 +662,12 @@ def _bytes_to_base64_data(data: bytes) -> str:
return fmt.format(mime=mime, data=b64)


if HAS_ORJSON:
if HAS_MSGSPEC:

def _to_json(obj: Any) -> str: # type: ignore
return orjson.dumps(obj).decode("utf-8")
return msgspec.json.encode(obj).decode("utf-8")

_from_json = orjson.loads # type: ignore
_from_json = msgspec.json.decode # type: ignore

else:

Expand Down
4 changes: 2 additions & 2 deletions requirements/speed.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
orjson>=3.5.4
aiohttp[speedups]
msgspec~=0.17.0
aiohttp[speedups]

0 comments on commit 0bd0313

Please sign in to comment.