tortoise / tortoise/tortoise-orm

could you use orjson in tortoise-orm?

Open
#598 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
5.6k
Forks
516
Avg merge
2d 21h
Merged PRs (30d)
9

Description

orjson is the fastest Python library for JSON, could you use orjson in tortoise-orm?
based on pydantic feature it is possible to use orjson on pydantic_model_creator in from tortoise.contrib.pydantic import pydantic_model_creator and instead of rapidjson in fields.data.py the code bellow:

try:
    # Use python-rapidjson as an optional accelerator
    import rapidjson

    JSON_DUMPS = rapidjson.dumps
    JSON_LOADS = rapidjson.loads
except ImportError:  # pragma: nocoverage
	pass

use this one based on answer

import importlib
orjson_spec = importlib.util.find_spec("orjson")
if orjson_spec:
	# Use orjson as an optional accelerator
	# pip install orjson 
    import orjson

    JSON_DUMPS = orsjon.dumps
    JSON_LOADS = orsjon.loads

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading pydantic_model_creator in tortoise.contrib.pydantic and the JSON handling in fields.data.py, especially the existing optional rapidjson import. Check how the requested orjson integration should apply in both locations and preserve the current fallback behavior. Done means the project uses optional orjson JSON handling as requested without breaking existing serialization paths.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
database
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.