<p align="center">
  <picture>
    <img alt="TextPy" src="docs/logo.png" width=50%>
  </picture>
</p>

# TextPy ── Collaborative Agent Workflow through Programming and Prompting

### 🚀 Core Philosophy

```
P1: Workflow = Programming + Prompting
P2: Programming <-> Prompting
P3: Workflow = Function Signature with Comment
```


### ⚡ Revolutionary Features
- **Mixed-Execution**: Seamlessly integrates with legacy code
- **AICompiler**: Just write function signatures -- our powerful compiler will automatically generate natural language instructions or code instructions just in time
- **Self-Replication**: Easier implementation of recursive workflows

### 🔧 Usage

#### Installation
Install via pip:
```bash
$ pip install textpy-llm
```
Import in your Python script:
```python
import textpy
```
Or use our Docker image:
```bash
$ docker pull ghcr.io/yezhengmao1/textpy:latest
```

### 👾 Quick Start - Amazing Example - Daily arXiv

**Example**: Automatically fetch daily updates from arXiv, filter papers by topic, translate abstracts into Chinese, store them in a database, and generate a markdown file to display the abstracts.

😊**Real-world Use Case**: I personally use **TextPy** to periodically push these generated markdown files to my blog when new papers are available.

Browse the results at: [Daily arXiv](https://yezhem.com/docs/Daily%20arXiv/)

**Highlight**: You only need to define the functions and use them in your workflow. Our powerful **AICompiler** recognizes their purpose, automatically generating and executing the necessary code or creating prompts for large language model interaction.

see `examples/daily_arxiv.py` for the complete implementation.

```python
@code
def get_the_rss_xml_file_str(*, url: str) -> str: ...

@code(pypi=[get_the_rss_xml_file_str(url=ARXIV_URL)])
def get_all_item_in_the_rss_file(*, xml_file_str: str) -> list[dict]: ...

@text
def check_topic_is_satisfactory(*, abstrct: str, topic: str) -> bool: ...

@text
def translate_the_en_abstract_to_zh(*, abstract: str) -> str: ...

@code
def check_link_in_db(*, db_path: str, link: str) -> bool: ...

@code
def save_article_to_db(*, db_path: str, item: dict): ...
# These functions only need to be defined...
```

### 🤩 Quick Start - Awesome Example - Deep Paper

**Example**: Download PDFs from arXiv using their IDs, extract text, generate summaries, and recursively process all cited references. The system visualizes the relationships between papers in an interactive HTML file.

**Highlight**: All functions in the workflow is generated by **TextPy**'s **AICompiler**, including installation and usage of external Python packages. Your only responsibility is writing function signatures with clear comments, and the workflow!

**NOTE**: We strongly recommend running this script in a container since the **AICompiler** manipulates the external environment during compilation.

To run with Docker:
```bash
cd ./examples
DEEPSEEK_API=xxx CACHE_DIR="/workspace/.cache" ARXIV_ID=<xxxx.xxxx> ./arxiv_search.sh
```

See It In Action:

<p align="center">
  <a href="https://www.youtube.com/watch?v=6EfpRPkiUVk">
    <img src="https://img.youtube.com/vi/6EfpRPkiUVk/0.jpg" alt="TextPy Example">
  </a>
</p>


### 📌 Contributing
Community contributions are more than welcome, whether it be to fix bugs or to add new features at github.

### 📜 Citation
```latex
@misc{ye2025textpy,
  author = {Zhengmao Ye, Shuyun Yang, Zelong Huang, Jie Zuo, Mingjie Tang},
  title = {TextPy: Collaborative Agent Workflow through Programming and Prompting},
  year = {2025},
  howpublished = {\url{https://github.com/yezhengmao1/TextPy}}
}
```