Search Options

Display Count
Sort
Preferred Language
Advanced Search

Results 1 - 10 of 1,293 for orjson (0.06 seconds)

  1. fastapi/responses.py

        and the
        [FastAPI docs for Response Model](https://fastapi.tiangolo.com/tutorial/response-model/).
    
        **Note**: `orjson` is not included with FastAPI and must be installed
        separately, e.g. `pip install orjson`.
        """
    
        def render(self, content: Any) -> bytes:
            assert orjson is not None, "orjson must be installed to use ORJSONResponse"
            return orjson.dumps(
    Created: Sun Apr 05 07:19:11 GMT 2026
    - Last Modified: Sun Mar 01 09:21:52 GMT 2026
    - 3.6K bytes
    - Click Count (0)
  2. docs_src/custom_response/tutorial009c_py310.py

    from typing import Any
    
    import orjson
    from fastapi import FastAPI, Response
    
    app = FastAPI()
    
    
    class CustomORJSONResponse(Response):
        media_type = "application/json"
    
        def render(self, content: Any) -> bytes:
            assert orjson is not None, "orjson must be installed"
            return orjson.dumps(content, option=orjson.OPT_INDENT_2)
    
    
    @app.get("/", response_class=CustomORJSONResponse)
    async def main():
    Created: Sun Apr 05 07:19:11 GMT 2026
    - Last Modified: Thu Feb 12 13:19:43 GMT 2026
    - 451 bytes
    - Click Count (0)
  3. docs/en/docs/advanced/custom-response.md

    You can create your own custom response class, inheriting from `Response` and using it.
    
    For example, let's say that you want to use [`orjson`](https://github.com/ijl/orjson) with some settings.
    
    Let's say you want it to return indented and formatted JSON, so you want to use the orjson option `orjson.OPT_INDENT_2`.
    
    Created: Sun Apr 05 07:19:11 GMT 2026
    - Last Modified: Thu Mar 05 18:13:19 GMT 2026
    - 11K bytes
    - Click Count (0)
  4. tests/test_default_response_class.py

    from typing import Any
    
    import orjson
    from fastapi import APIRouter, FastAPI
    from fastapi.responses import HTMLResponse, JSONResponse, PlainTextResponse
    from fastapi.testclient import TestClient
    
    
    class ORJSONResponse(JSONResponse):
        media_type = "application/x-orjson"
    
        def render(self, content: Any) -> bytes:
            return orjson.dumps(content)
    
    
    class OverrideResponse(JSONResponse):
        media_type = "application/x-override"
    Created: Sun Apr 05 07:19:11 GMT 2026
    - Last Modified: Sun Mar 01 20:49:20 GMT 2020
    - 5.2K bytes
    - Click Count (0)
  5. docs/zh-hant/docs/advanced/custom-response.md

    ```json
    {
      "message": "Hello World"
    }
    ```
    
    當然,你大概能找到比格式化 JSON 更好的方式來利用這個能力。😉
    
    ### `orjson` 或回應模型 { #orjson-or-response-model }
    
    如果你追求效能,使用[回應模型](../tutorial/response-model.md) 大概會比使用 `orjson` 回應更好。
    
    有了回應模型,FastAPI 會使用 Pydantic 直接將資料序列化為 JSON,而不需要像其他情況那樣先經過 `jsonable_encoder` 之類的中介步驟。
    
    而且在底層,Pydantic 用來序列化為 JSON 的 Rust 機制和 `orjson` 相同,因此用回應模型已經能獲得最佳效能。
    
    ## 預設回應類別 { #default-response-class }
    
    Created: Sun Apr 05 07:19:11 GMT 2026
    - Last Modified: Fri Mar 20 17:05:38 GMT 2026
    - 10.3K bytes
    - Click Count (0)
  6. docs/en/docs/reference/responses.md

    ::: fastapi.responses.UJSONResponse
        options:
            members:
                - charset
                - status_code
                - media_type
                - body
                - background
                - raw_headers
                - render
                - init_headers
                - headers
                - set_cookie
    Created: Sun Apr 05 07:19:11 GMT 2026
    - Last Modified: Sun Feb 22 16:34:59 GMT 2026
    - 4.4K bytes
    - Click Count (0)
  7. tests/test_deprecated_responses.py

            response = client.get("/items")
        assert response.status_code == 200
        assert response.json() == {"name": "widget", "price": 9.99}
    
    
    def test_orjson_response_emits_deprecation_warning():
        with pytest.warns(FastAPIDeprecationWarning, match="ORJSONResponse is deprecated"):
            ORJSONResponse(content={"hello": "world"})
    
    
    # UJSON
    
    
    def _make_ujson_app() -> FastAPI:
        with warnings.catch_warnings():
    Created: Sun Apr 05 07:19:11 GMT 2026
    - Last Modified: Sun Feb 22 16:34:59 GMT 2026
    - 2K bytes
    - Click Count (0)
  8. pyproject.toml

        "python-slugify >=8.0.4",
        "pyyaml >=5.3.1,<7.0.0",
        "typer >=0.21.1",
    ]
    docs-tests = [
        "httpx >=0.23.0,<1.0.0",
        "ruff >=0.14.14",
        # For UJSONResponse
        "ujson >=5.8.0",
        # For ORJSONResponse
        "orjson >=3.9.3",
    ]
    github-actions = [
        "httpx >=0.27.0,<1.0.0",
        "pydantic >=2.9.0,<3.0.0",
        "pydantic-settings >=2.1.0,<3.0.0",
        "pygithub >=2.3.0,<3.0.0",
    Created: Sun Apr 05 07:19:11 GMT 2026
    - Last Modified: Mon Mar 23 12:36:49 GMT 2026
    - 10.3K bytes
    - Click Count (0)
  9. docs/de/docs/index.md

    Zusätzliche optionale FastAPI-Abhängigkeiten:
    
    * [`orjson`](https://github.com/ijl/orjson) – erforderlich, wenn Sie `ORJSONResponse` verwenden möchten.
    * [`ujson`](https://github.com/esnme/ultrajson) – erforderlich, wenn Sie `UJSONResponse` verwenden möchten.
    
    ## Lizenz { #license }
    
    Created: Sun Apr 05 07:19:11 GMT 2026
    - Last Modified: Thu Mar 19 17:58:09 GMT 2026
    - 23.6K bytes
    - Click Count (1)
  10. docs/uk/docs/index.md

    Додаткові необовʼязкові залежності FastAPI:
    
    * [`orjson`](https://github.com/ijl/orjson) - потрібно, якщо ви хочете використовувати `ORJSONResponse`.
    * [`ujson`](https://github.com/esnme/ultrajson) - потрібно, якщо ви хочете використовувати `UJSONResponse`.
    
    ## Ліцензія { #license }
    
    Created: Sun Apr 05 07:19:11 GMT 2026
    - Last Modified: Thu Mar 19 18:27:41 GMT 2026
    - 29.1K bytes
    - Click Count (0)
Back to Top