Introduction
sync2llmtxt is a script designed to automatically aggregate source code files from a specified directory into a single text file in a target directory. This facilitates providing the entire project code as context to large language models (e.g., LLM/LLMtxt). The script supports automatic directory monitoring for real-time updates to the aggregated document, as well as manual execution for one-time generation.
中文 English
Use Cases
You can specify the target file as a directory in Google Drive, allowing the project code to be aggregated into Google Drive for easy use with Gemini.
Key Features
- Multi-file Type Support: Aggregates
.py,.ts,.tsx,.js,.json,.md, and other common code and text files. - Smart Ignore:
- Automatically applies
.gitignorerules. - Supports custom
IGNORE_PATTERNS. - Excludes binary files, images, and other irrelevant content.
- Automatically applies
- Directory Structure Export: Generates a clean tree-like directory structure (including ignored markers).
- Flexible Configuration:
- Supports YAML configuration files.
- Command-line parameter overrides.
- Advanced Filtering:
- Filters by file size (
--max-size). - Filters by modification time (
--since-days).
- Filters by file size (
- Detailed Logging: Multi-level logging for debugging.
Installation
Option 1: Install from PyPI (Recommended)
pip install sync2llmtxt
Option 2: Install from Source
# Clone the repository
git clone https://github.com/yourusername/sync2llmtxt.git
cd sync2llmtxt
# Install in development mode
pip install -e .
# For development dependencies (optional)
pip install -r requirements-test.txt
Configuration
1. Configuration File (YAML)
MONITORED_CODE_DIR: /path/to/code
OUTPUT_DOCUMENT_PATH: /path/to/output.txt
CODE_FILE_PATTERNS:
- '*.py'
- '*.md'
IGNORE_PATTERNS:
- node_modules
ENABLE_AUTOMATIC_MONITORING: true
DEBOUNCE_TIME: 2.0
2. Command-Line Arguments
| Argument | Description | Example |
|---|---|---|
-s/--src |
Source code directory | -s ./src |
-o/--out |
Output file path | -o output.txt |
-c/--config |
Configuration file path | -c config.yaml |
--max-size |
Maximum file size (MB) | --max-size 2 |
--since-days |
Days since last modification | --since-days 7 |
Usage Examples
# Basic usage
sync2llmtxt -s ./project -o output.txt
# Use config file + filter large files
sync2llmtxt -c config.yaml --max-size 1.5
# Sync only recently modified files
sync2llmtxt -s ./src -o out.txt --since-days 3
Testing (Pending)
# Run tests
pytest --cov=.
# Generate test coverage report
pytest --cov=. --cov-report=html
Output Format Example
--- Project Code Context (Manual Run @ 2023-11-15 10:00:00) ---
Included Files (2):
- main.py
- utils/helper.py
--- File: main.py ---
import utils
if __name__ == "__main__":
print("Hello")
--- File: utils/helper.py ---
def help():
return "Help message"
--- Directory Structure ---
project/
├── main.py
└── utils/
└── helper.py
Development Guide
Code Structure
src/sync2llmtxt/sync2llmtxt.py: Main program.src/sync2llmtxt/directory_tree.py: Directory tree generation module.tests/: Unit tests.
Extension Suggestions
- Add support for more file types.
- Implement incremental update mode.
- Support remote storage for output.
License
MIT License
Metadata
Release files for sync2llmtxt 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| sync2llmtxt-0.1.0.tar.gz | 16.3 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| sync2llmtxt-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 29.8 kB
Release files / sync2llmtxt-0.1.0.tar.gz
| Download URL | sync2llmtxt-0.1.0.tar.gz |
|---|---|
| Size | 16.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f183ef8ccc4fb645d54646559034844ec0e603e8647759eee62d8a713967bd72
|
|
BLAKE2b-256 checksum How to use checksums |
cfd5a3f03e3eb9e387f529af460a8eba31d8f387abf0c0f8255cb8c027cc260a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.3
|
Release files / sync2llmtxt-0.1.0-py3-none-any.whl
| Download URL | sync2llmtxt-0.1.0-py3-none-any.whl |
|---|---|
| Size | 13.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e9aae7b5d9dd337801e458052d902f7a93e984927f73216f386745d5aa1d4a6b
|
|
BLAKE2b-256 checksum How to use checksums |
b6089d826a430391e0328f3e05a9f793098802e41db25ae239ed603e320032eb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.3
|
Security for sync2llmtxt 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.