1{
2 lib,
3 stdenv,
4 buildPythonPackage,
5 fetchFromGitHub,
6 pythonOlder,
7
8 # build-system
9 rustPlatform,
10 cffi,
11
12 # native dependencies
13 libiconv,
14
15 # tests
16 numpy,
17 psutil,
18 pytestCheckHook,
19 python-dateutil,
20 pytz,
21 xxhash,
22 python,
23
24 # for passthru.tests
25 falcon,
26 fastapi,
27 gradio,
28 mashumaro,
29 ufolib2,
30}:
31
32buildPythonPackage rec {
33 pname = "orjson";
34 version = "3.10.1";
35 pyproject = true;
36
37 disabled = pythonOlder "3.8";
38
39 src = fetchFromGitHub {
40 owner = "ijl";
41 repo = "orjson";
42 rev = "refs/tags/${version}";
43 hash = "sha256-vEJriLd7f+zlYcMIyhDTkq2kmNc5MaNLHo0qMLS5hro=";
44 };
45
46 cargoDeps = rustPlatform.fetchCargoTarball {
47 inherit src;
48 name = "${pname}-${version}";
49 hash = "sha256-yQkpjedHwgsZiiZEzYV66aa9RepCFW0PBqtD29tfoMI=";
50 };
51
52 maturinBuildFlags = [ "--interpreter ${python.executable}" ];
53
54 nativeBuildInputs =
55 [ cffi ]
56 ++ (with rustPlatform; [
57 cargoSetupHook
58 maturinBuildHook
59 ]);
60
61 buildInputs = lib.optionals stdenv.isDarwin [ libiconv ];
62
63 nativeCheckInputs = [
64 numpy
65 psutil
66 pytestCheckHook
67 python-dateutil
68 pytz
69 xxhash
70 ];
71
72 pythonImportsCheck = [ "orjson" ];
73
74 passthru.tests = {
75 inherit
76 falcon
77 fastapi
78 gradio
79 mashumaro
80 ufolib2
81 ;
82 };
83
84 meta = with lib; {
85 description = "Fast, correct Python JSON library supporting dataclasses, datetimes, and numpy";
86 homepage = "https://github.com/ijl/orjson";
87 changelog = "https://github.com/ijl/orjson/blob/${version}/CHANGELOG.md";
88 license = with licenses; [
89 asl20
90 mit
91 ];
92 platforms = platforms.unix;
93 maintainers = with maintainers; [ misuzu ];
94 };
95}