Metadata-Version: 2.4
Name: dictree-sprint
Version: 0.1.0
Summary: A lightweight tool to visualize the structure of nested Python dictionaries and lists as a tree.
Author-email: Your Name <your.email@example.com>
License: MIT
Project-URL: Homepage, https://github.com/yourusername/dictree
Keywords: dict,tree,structure,visualize,schema,debug
Classifier: Programming Language :: Python :: 3
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Intended Audience :: Developers
Classifier: Topic :: Software Development :: Debuggers
Requires-Python: >=3.10
Description-Content-Type: text/markdown

# Dictree

`dictree` 是一个轻量级的 Python 工具，用于以树状结构可视化复杂的嵌套字典（Dict）、列表（List）、元组（Tuple）和集合（Set）。它旨在帮助开发者快速了解复杂数据结构的 **Schema (架构)**，而不会被具体的数值所淹没。

---

## 🚀 特性

- **结构化展示**：模仿 Unix `tree` 命令的样式展示嵌套结构。
- **智能代表提取**：对于列表或集合，自动识别其中的元素类型。如果列表中包含字典或嵌套容器，会提取其结构作为代表。
- **深度控制**：通过 `max_depth` 参数防止无限展开或处理超大型对象。
- **自定义模板**：可以自定义列表/容器的统计信息展示格式。
- **输出灵活**：支持直接打印到控制台或返回字符串。

---

## 📦 安装

目前可以通过源码安装：

```bash
pip install .
```

---

## 🛠️ 快速上手

### 1. 基本用法

直接打印一个复杂的嵌套字典：

```python
from dictree import sprint

data = {
    "users": [
        {
            "id": 1,
            "profile": {
                "name": "Alice",
                "hobbies": ["coding", "reading"]
            }
        },
        {
            "id": 2,
            "profile": {
                "name": "Bob",
                "hobbies": ["gaming"]
            }
        }
    ],
    "status": "success",
    "meta": {"page": 1, "total": 100}
}

sprint(data)
```

**输出：**
```text
├── users
│   └── [2]: dict
│       ├── id
│       └── profile
│           ├── name
│           └── hobbies
│               └── [2]: str
├── status
└── meta
    ├── page
    └── total
```

### 2. 限制展开深度

当对象非常庞大时，可以使用 `max_depth` 参数：

```python
sprint(data, max_depth=1)
```

**输出：**
```text
├── users
│   └── … (depth limit)
├── status
└── meta
    └── … (depth limit)
```

### 3. 获取字符串而不是打印

如果你需要将结果保存到日志或文件中：

```python
tree_str = sprint(data, return_string=True)
print(f"Captured Tree:\n{tree_str}")
```

### 4. 自定义列表格式

你可以利用 `list_repr_template` 改变列表项的显示方式。
默认模板为 `"{count}: {repr}"`。

```python
sprint(data, list_repr_template="[{count} elements of {repr}]")
```

**输出示例：**
```text
├── users
│   └── [2 elements of dict]
...
```

---

## 💡 为什么使用 dictree?

在处理爬虫返回的 JSON、大型 API 响应或复杂的配置文件时，`print()` 或 `pprint` 往往会输出成千上万行数据。`dictree` 通过隐藏具体的“值”，只提取“键”和“容器类型”，让你在一屏之内看清数据的所有层级和结构。

---

## 📄 开源协议

MIT License
