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. 4 imports, 1 dependents.

File python AnthropicClient AsyncAPI 4 imports 1 dependents 4 functions

Entity Profile

Dependency Diagram

graph LR
  b21d65c1_1f1b_5699_6638_2ab0107a8fb1["_files.py"]
  b39817e4_aad6_041a_fe95_e3025b6a7382["_types"]
  b21d65c1_1f1b_5699_6638_2ab0107a8fb1 --> b39817e4_aad6_041a_fe95_e3025b6a7382
  bb0af148_44a9_df40_49c4_0fa6ceb5a403["os"]
  b21d65c1_1f1b_5699_6638_2ab0107a8fb1 --> bb0af148_44a9_df40_49c4_0fa6ceb5a403
  525f4270_cbfe_512c_fbe4_e6566e0cdf13["pathlib"]
  b21d65c1_1f1b_5699_6638_2ab0107a8fb1 --> 525f4270_cbfe_512c_fbe4_e6566e0cdf13
  40396b02_9c68_4765_9e00_db68fce91470["anyio"]
  b21d65c1_1f1b_5699_6638_2ab0107a8fb1 --> 40396b02_9c68_4765_9e00_db68fce91470
  283557ff_0a7d_4f9f_e620_287b605a88e8["__init__.py"]
  283557ff_0a7d_4f9f_e620_287b605a88e8 --> b21d65c1_1f1b_5699_6638_2ab0107a8fb1
  style b21d65c1_1f1b_5699_6638_2ab0107a8fb1 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

from __future__ import annotations

import os
from pathlib import Path

import anyio

from .._types import FileTypes


def files_from_dir(directory: str | os.PathLike[str]) -> list[FileTypes]:
    path = Path(directory)

    files: list[FileTypes] = []
    _collect_files(path, path.parent, files)
    return files


def _collect_files(directory: Path, relative_to: Path, files: list[FileTypes]) -> None:
    for path in directory.iterdir():
        if path.is_dir():
            _collect_files(path, relative_to, files)
            continue

        files.append((path.relative_to(relative_to).as_posix(), path.read_bytes()))


async def async_files_from_dir(directory: str | os.PathLike[str]) -> list[FileTypes]:
    path = anyio.Path(directory)

    files: list[FileTypes] = []
    await _async_collect_files(path, path.parent, files)
    return files


async def _async_collect_files(directory: anyio.Path, relative_to: anyio.Path, files: list[FileTypes]) -> None:
    async for path in directory.iterdir():
        if await path.is_dir():
            await _async_collect_files(path, relative_to, files)
            continue

        files.append((path.relative_to(relative_to).as_posix(), await path.read_bytes()))

Subdomains

Dependencies

  • _types
  • anyio
  • os
  • pathlib

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 4 function(s): _async_collect_files, _collect_files, async_files_from_dir, files_from_dir.
What does _files.py depend on?
_files.py imports 4 module(s): _types, anyio, os, pathlib.
What files import _files.py?
_files.py is imported by 1 file(s): __init__.py.
Where is _files.py in the architecture?
_files.py is located at src/anthropic/lib/_files.py (domain: AnthropicClient, subdomain: AsyncAPI, directory: src/anthropic/lib).

Analyze Your Own Codebase

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

Try Supermodel Free