Last modified: Jun 08, 2026

Install Orjson in Python Guide

Orjson is a fast JSON library for Python. It is written in Rust. It can parse and serialize JSON much faster than the standard json module. This makes it great for high-performance applications.

Installing Orjson is usually simple. But sometimes you might face errors. This guide will help you install Orjson on any system. We will cover pip, conda, and common problems.

Why Use Orjson?

Orjson is very fast. It is often 3x to 10x faster than Python's built-in JSON library. It also has features like serializing NumPy arrays and dataclasses directly. If you work with large JSON data, Orjson can save you time.

It is also memory efficient. Orjson uses a custom serializer. This keeps memory usage low during parsing.

System Requirements

Orjson requires a Rust compiler. This is because Orjson is written in Rust. On most systems, pip will download a pre-built wheel. But if no wheel is available for your system, pip will try to compile from source. This requires Rust.

You also need Python 3.7 or newer. Orjson does not support older Python versions.

How to Install Orjson with Pip

The easiest way is to use pip. Open your terminal or command prompt. Run this command:

 
pip install orjson

If you are using Python 3, you might need to use pip3 instead:

 
pip3 install orjson

This command will download and install Orjson. The process usually takes a few seconds. If it works, you will see a success message.

To verify the installation, run Python and import Orjson:

 
import orjson
print(orjson.__version__)

If no error appears, Orjson is ready to use.

How to Install Orjson with Conda

If you use Anaconda or Miniconda, you can install Orjson from the conda-forge channel. Run:

 
conda install -c conda-forge orjson

This command works on Windows, macOS, and Linux. Conda will handle dependencies automatically.

You can also create a new environment and install Orjson there:

 
conda create -n myenv python=3.10
conda activate myenv
conda install -c conda-forge orjson

Using a separate environment helps avoid package conflicts.

Installing Orjson from Source

Sometimes you need to install from source. This happens when no pre-built wheel is available. For example, on some ARM systems or custom Linux distributions.

First, install Rust. The easiest way is to use rustup:

 
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

Follow the on-screen instructions. After Rust is installed, restart your terminal. Then install Orjson with pip:

 
pip install orjson --no-binary :all:

The --no-binary :all: flag forces pip to compile from source. This might take a few minutes. Once done, Orjson will be installed.

Common Installation Errors

Many beginners face errors when installing Orjson. Here are the most common ones and their fixes.

Error: "Failed building wheel for orjson"

This error usually means Rust is missing. Install Rust first, then try again. On Windows, you can also install Rust from the official website.

Another cause is a missing C compiler. On Linux, you need build-essential. Install it with:

 
sudo apt update
sudo apt install build-essential

On macOS, install Xcode command line tools:

 
xcode-select --install

Error: "No matching distribution found for orjson"

This error means pip cannot find a version of Orjson for your Python version. Make sure you are using Python 3.7 or newer. Check your Python version:

 
python --version

If your Python is too old, upgrade it. You can also use a virtual environment with a newer Python.

Error: "Permission denied"

This happens when you try to install Orjson globally without admin rights. Use a virtual environment or add the --user flag:

 
pip install --user orjson

Testing Your Installation

Once Orjson is installed, test it with a simple script. Create a file named test_orjson.py and add this code:

 
import orjson

# Sample data
data = {"name": "Alice", "age": 30, "city": "New York"}

# Serialize to JSON bytes
json_bytes = orjson.dumps(data)
print("Serialized:", json_bytes)

# Deserialize back to dict
parsed = orjson.loads(json_bytes)
print("Parsed:", parsed)

Run the script:

 
python test_orjson.py

You should see output like this:

 
Serialized: b'{"name":"Alice","age":30,"city":"New York"}'
Parsed: {'name': 'Alice', 'age': 30, 'city': 'New York'}

If you see this output, your installation works correctly.

Using Orjson in Your Projects

Orjson is easy to use. The main functions are dumps and loads. They work like Python's json.dumps and json.loads but are much faster.

Here is an example of serializing a dataclass:

 
import orjson
from dataclasses import dataclass

@dataclass
class Person:
    name: str
    age: int

person = Person("Bob", 25)
json_bytes = orjson.dumps(person)
print(json_bytes)  # b'{"name":"Bob","age":25}'

Orjson also handles NumPy arrays natively. This is very useful for data science projects.

 
import orjson
import numpy as np

arr = np.array([1, 2, 3, 4, 5])
json_bytes = orjson.dumps(arr)
print(json_bytes)  # b'[1,2,3,4,5]'

Uninstalling Orjson

If you need to remove Orjson, use pip:

 
pip uninstall orjson

Or with conda:

 
conda remove orjson

Conclusion

Installing Orjson in Python is simple. Use pip or conda for a quick setup. If you face errors, check your Rust installation and Python version. Orjson is a powerful tool for fast JSON processing. Once installed, it can significantly speed up your Python applications. Use it in projects that need high performance, like web APIs, data pipelines, and machine learning services.