Home / File/ encoders.py — fastapi Source File

encoders.py — fastapi Source File

Architecture documentation for encoders.py, a python file in the fastapi codebase. 20 imports, 14 dependents.

File python FastAPI Routing 20 imports 14 dependents 4 functions

Entity Profile

Dependency Diagram

graph LR
  ea747667_035c_8539_a8f7_f347fb7e7c39["encoders.py"]
  aac750d7_00e7_a28d_9e64_89918311078b["__init__.py"]
  ea747667_035c_8539_a8f7_f347fb7e7c39 --> aac750d7_00e7_a28d_9e64_89918311078b
  4cff5a35_9399_b238_3d2b_e2cca82878e1["dataclasses"]
  ea747667_035c_8539_a8f7_f347fb7e7c39 --> 4cff5a35_9399_b238_3d2b_e2cca82878e1
  e973e384_8276_b242_eb98_1c0b79a84e68["datetime"]
  ea747667_035c_8539_a8f7_f347fb7e7c39 --> e973e384_8276_b242_eb98_1c0b79a84e68
  36df6c22_bdda_c58d_8489_1b2bca07e51a["collections"]
  ea747667_035c_8539_a8f7_f347fb7e7c39 --> 36df6c22_bdda_c58d_8489_1b2bca07e51a
  f9d54b01_68e2_bbed_c8ee_3f6749520bcb["decimal"]
  ea747667_035c_8539_a8f7_f347fb7e7c39 --> f9d54b01_68e2_bbed_c8ee_3f6749520bcb
  712b7268_fde0_3ca8_dc06_7aa9a47c77d9["enum"]
  ea747667_035c_8539_a8f7_f347fb7e7c39 --> 712b7268_fde0_3ca8_dc06_7aa9a47c77d9
  949c11e1_f075_f37c_e813_82561eff92c7["ipaddress"]
  ea747667_035c_8539_a8f7_f347fb7e7c39 --> 949c11e1_f075_f37c_e813_82561eff92c7
  b3e303a2_3f2d_638d_930c_3a5dcc2f5a42["pathlib"]
  ea747667_035c_8539_a8f7_f347fb7e7c39 --> b3e303a2_3f2d_638d_930c_3a5dcc2f5a42
  b423f231_0305_b686_5fea_7c66fe42f25b["re"]
  ea747667_035c_8539_a8f7_f347fb7e7c39 --> b423f231_0305_b686_5fea_7c66fe42f25b
  57435f98_d97c_449e_ad42_afacbc7e4272["types.py"]
  ea747667_035c_8539_a8f7_f347fb7e7c39 --> 57435f98_d97c_449e_ad42_afacbc7e4272
  0dda2280_3359_8460_301c_e98c77e78185["typing"]
  ea747667_035c_8539_a8f7_f347fb7e7c39 --> 0dda2280_3359_8460_301c_e98c77e78185
  90bacbf7_ee4e_4955_c1b3_1214f56df7b1["uuid"]
  ea747667_035c_8539_a8f7_f347fb7e7c39 --> 90bacbf7_ee4e_4955_c1b3_1214f56df7b1
  5efacb44_5373_ceb9_9579_6e6603820488["annotated_doc"]
  ea747667_035c_8539_a8f7_f347fb7e7c39 --> 5efacb44_5373_ceb9_9579_6e6603820488
  01c652c5_d85c_f45e_848e_412c94ea4172["exceptions.py"]
  ea747667_035c_8539_a8f7_f347fb7e7c39 --> 01c652c5_d85c_f45e_848e_412c94ea4172
  style ea747667_035c_8539_a8f7_f347fb7e7c39 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import dataclasses
import datetime
from collections import defaultdict, deque
from decimal import Decimal
from enum import Enum
from ipaddress import (
    IPv4Address,
    IPv4Interface,
    IPv4Network,
    IPv6Address,
    IPv6Interface,
    IPv6Network,
)
from pathlib import Path, PurePath
from re import Pattern
from types import GeneratorType
from typing import Annotated, Any, Callable, Optional, Union
from uuid import UUID

from annotated_doc import Doc
from fastapi.exceptions import PydanticV1NotSupportedError
from fastapi.types import IncEx
from pydantic import BaseModel
from pydantic.color import Color
from pydantic.networks import AnyUrl, NameEmail
from pydantic.types import SecretBytes, SecretStr
from pydantic_core import PydanticUndefinedType

from ._compat import (
    Url,
    is_pydantic_v1_model_instance,
)


# Taken from Pydantic v1 as is
def isoformat(o: Union[datetime.date, datetime.time]) -> str:
    return o.isoformat()


# Adapted from Pydantic v1
# TODO: pv2 should this return strings instead?
def decimal_encoder(dec_value: Decimal) -> Union[int, float]:
    """
    Encodes a Decimal as int if there's no exponent, otherwise float

    This is useful when we use ConstrainedDecimal to represent Numeric(x,0)
    where an integer (but not int typed) is used. Encoding this as a float
    results in failed round-tripping between encode and parse.
    Our Id type is a prime example of this.

    >>> decimal_encoder(Decimal("1.0"))
    1.0

    >>> decimal_encoder(Decimal("1"))
    1

    >>> decimal_encoder(Decimal("NaN"))
    nan
    """
    exponent = dec_value.as_tuple().exponent
// ... (287 more lines)

Domain

Subdomains

Dependencies

Frequently Asked Questions

What does encoders.py do?
encoders.py is a source file in the fastapi codebase, written in python. It belongs to the FastAPI domain, Routing subdomain.
What functions are defined in encoders.py?
encoders.py defines 4 function(s): decimal_encoder, generate_encoders_by_class_tuples, isoformat, jsonable_encoder.
What does encoders.py depend on?
encoders.py imports 20 module(s): PydanticV1NotSupportedError, __init__.py, annotated_doc, collections, dataclasses, datetime, decimal, enum, and 12 more.
What files import encoders.py?
encoders.py is imported by 14 file(s): docs.py, exception_handlers.py, routing.py, test_jsonable_encoder.py, tutorial001_py310.py, tutorial001_py310.py, tutorial001_py310.py, tutorial001_py39.py, and 6 more.
Where is encoders.py in the architecture?
encoders.py is located at fastapi/encoders.py (domain: FastAPI, subdomain: Routing, directory: fastapi).

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free