Home / File/ _files.py — anthropic-sdk-python Source File

_files.py — anthropic-sdk-python Source File

Architecture documentation for _files.py, a python file in the anthropic-sdk-python codebase. 9 imports, 1 dependents.

File python AnthropicClient AsyncAPI 9 imports 1 dependents 9 functions

Entity Profile

Dependency Diagram

graph LR
  e20f2c32_b105_01cb_557f_c10174db767d["_files.py"]
  87f621ac_b3e0_a225_72b3_99f9818f3002["_types.py"]
  e20f2c32_b105_01cb_557f_c10174db767d --> 87f621ac_b3e0_a225_72b3_99f9818f3002
  78563632_ba46_133e_95c2_a2ef496152fc["Base64FileInput"]
  e20f2c32_b105_01cb_557f_c10174db767d --> 78563632_ba46_133e_95c2_a2ef496152fc
  6dadb144_3070_6111_357f_214554108905["__init__.py"]
  e20f2c32_b105_01cb_557f_c10174db767d --> 6dadb144_3070_6111_357f_214554108905
  3ee9df07_3d82_3549_bc64_a6db4e026506["io"]
  e20f2c32_b105_01cb_557f_c10174db767d --> 3ee9df07_3d82_3549_bc64_a6db4e026506
  bb0af148_44a9_df40_49c4_0fa6ceb5a403["os"]
  e20f2c32_b105_01cb_557f_c10174db767d --> bb0af148_44a9_df40_49c4_0fa6ceb5a403
  525f4270_cbfe_512c_fbe4_e6566e0cdf13["pathlib"]
  e20f2c32_b105_01cb_557f_c10174db767d --> 525f4270_cbfe_512c_fbe4_e6566e0cdf13
  89ddcdd7_3ae1_4c7b_41bb_9f1e25f16875["typing"]
  e20f2c32_b105_01cb_557f_c10174db767d --> 89ddcdd7_3ae1_4c7b_41bb_9f1e25f16875
  37c05070_ca59_d596_7250_de9d1939227f["typing_extensions"]
  e20f2c32_b105_01cb_557f_c10174db767d --> 37c05070_ca59_d596_7250_de9d1939227f
  40396b02_9c68_4765_9e00_db68fce91470["anyio"]
  e20f2c32_b105_01cb_557f_c10174db767d --> 40396b02_9c68_4765_9e00_db68fce91470
  31e60ad8_cac8_652d_176d_4f7cf7dda1ad["_base_client.py"]
  31e60ad8_cac8_652d_176d_4f7cf7dda1ad --> e20f2c32_b105_01cb_557f_c10174db767d
  style e20f2c32_b105_01cb_557f_c10174db767d fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

from __future__ import annotations

import io
import os
import pathlib
from typing import overload
from typing_extensions import TypeGuard

import anyio

from ._types import (
    FileTypes,
    FileContent,
    RequestFiles,
    HttpxFileTypes,
    Base64FileInput,
    HttpxFileContent,
    HttpxRequestFiles,
)
from ._utils import is_tuple_t, is_mapping_t, is_sequence_t


def is_base64_file_input(obj: object) -> TypeGuard[Base64FileInput]:
    return isinstance(obj, io.IOBase) or isinstance(obj, os.PathLike)


def is_file_content(obj: object) -> TypeGuard[FileContent]:
    return (
        isinstance(obj, bytes) or isinstance(obj, tuple) or isinstance(obj, io.IOBase) or isinstance(obj, os.PathLike)
    )


def assert_is_file_content(obj: object, *, key: str | None = None) -> None:
    if not is_file_content(obj):
        prefix = f"Expected entry at `{key}`" if key is not None else f"Expected file input `{obj!r}`"
        raise RuntimeError(
            f"{prefix} to be bytes, an io.IOBase instance, PathLike or a tuple but received {type(obj)} instead. See https://github.com/anthropics/anthropic-sdk-python/tree/main#file-uploads"
        ) from None


@overload
def to_httpx_files(files: None) -> None: ...


@overload
def to_httpx_files(files: RequestFiles) -> HttpxRequestFiles: ...


def to_httpx_files(files: RequestFiles | None) -> HttpxRequestFiles | None:
    if files is None:
        return None

    if is_mapping_t(files):
        files = {key: _transform_file(file) for key, file in files.items()}
    elif is_sequence_t(files):
        files = [(key, _transform_file(file)) for key, file in files]
    else:
        raise TypeError(f"Unexpected file type input {type(files)}, expected mapping or sequence")

    return files
// ... (64 more lines)

Subdomains

Dependencies

Frequently Asked Questions

What does _files.py do?
_files.py is a source file in the anthropic-sdk-python codebase, written in python. It belongs to the AnthropicClient domain, AsyncAPI subdomain.
What functions are defined in _files.py?
_files.py defines 9 function(s): _async_transform_file, _transform_file, assert_is_file_content, async_read_file_content, async_to_httpx_files, is_base64_file_input, is_file_content, read_file_content, to_httpx_files.
What does _files.py depend on?
_files.py imports 9 module(s): Base64FileInput, __init__.py, _types.py, anyio, io, os, pathlib, typing, and 1 more.
What files import _files.py?
_files.py is imported by 1 file(s): _base_client.py.
Where is _files.py in the architecture?
_files.py is located at src/anthropic/_files.py (domain: AnthropicClient, subdomain: AsyncAPI, directory: src/anthropic).

Analyze Your Own Codebase

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

Try Supermodel Free