Personal-use NixOS configuration
1# https://github.com/NixOS/nixpkgs/blob/5ae3b07d8d6527c42f17c876e404993199144b6a/pkgs/development/python-modules/fastapi/default.nix#L140
2# Won't be needed once NixOS 25.11 releases
3
4{
5 lib,
6 python3,
7 buildPythonPackage ? python3.pkgs.buildPythonPackage,
8 fetchFromGitHub,
9 pythonOlder ? python3.pkgs.pythonOlder,
10}:
11
12buildPythonPackage rec {
13 pname = "fastapi";
14 version = "0.116.1";
15 pyproject = true;
16
17 disabled = pythonOlder "3.7";
18
19 src = fetchFromGitHub {
20 owner = "tiangolo";
21 repo = "fastapi";
22 tag = version;
23 hash = "sha256-sd0SnaxuuF3Zaxx7rffn4ttBpRmWQoOtXln/amx9rII=";
24 };
25
26 build-system = with python3.pkgs; [ pdm-backend ];
27
28 pythonRelaxDeps = [
29 "anyio"
30 "starlette"
31 ];
32
33 dependencies = with python3.pkgs; [
34 starlette
35 pydantic
36 typing-extensions
37 ];
38
39 optional-dependencies = {
40 all =
41 with python3.pkgs;
42 [
43 fastapi-cli
44 httpx
45 jinja2
46 python-multipart
47 itsdangerous
48 pyyaml
49 ujson
50 orjson
51 email-validator
52 uvicorn
53 ]
54 ++ lib.optionals (lib.versionAtLeast pydantic.version "2") [
55 pydantic-settings
56 pydantic-extra-types
57 ]
58 ++ fastapi-cli.optional-dependencies.standard
59 ++ uvicorn.optional-dependencies.standard;
60 standard =
61 with python3.pkgs;
62 [
63 fastapi-cli
64 httpx
65 jinja2
66 python-multipart
67 email-validator
68 uvicorn
69 ]
70 ++ fastapi-cli.optional-dependencies.standard
71 ++ uvicorn.optional-dependencies.standard;
72 };
73
74 nativeCheckInputs =
75 with python3.pkgs;
76 [
77 anyio
78 dirty-equals
79 flask
80 inline-snapshot
81 passlib
82 pyjwt
83 pytestCheckHook
84 pytest-asyncio
85 trio
86 sqlalchemy
87 ]
88 ++ anyio.optional-dependencies.trio
89 ++ passlib.optional-dependencies.bcrypt
90 ++ optional-dependencies.all;
91
92 pytestFlags = [
93 # ignoring deprecation warnings to avoid test failure from
94 # tests/test_tutorial/test_testing/test_tutorial001.py
95 "-Wignore::DeprecationWarning"
96 "-Wignore::pytest.PytestUnraisableExceptionWarning"
97 ];
98
99 disabledTests = [
100 # Coverage test
101 "test_fastapi_cli"
102 # Likely pydantic compat issue
103 "test_exception_handler_body_access"
104 ];
105
106 disabledTestPaths = [
107 # Don't test docs and examples
108 "docs_src"
109 "tests/test_tutorial/test_sql_databases"
110 ];
111
112 pythonImportsCheck = [ "fastapi" ];
113
114 meta = with lib; {
115 changelog = "https://github.com/fastapi/fastapi/releases/tag/${src.tag}";
116 description = "Web framework for building APIs";
117 homepage = "https://github.com/fastapi/fastapi";
118 license = licenses.mit;
119 maintainers = with maintainers; [ wd15 ];
120 };
121}