accrue 1.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- accrue-1.0.0/.gitignore +110 -0
- accrue-1.0.0/LICENSE +21 -0
- accrue-1.0.0/PKG-INFO +207 -0
- accrue-1.0.0/README.md +157 -0
- accrue-1.0.0/accrue/__init__.py +77 -0
- accrue-1.0.0/accrue/core/__init__.py +40 -0
- accrue-1.0.0/accrue/core/cache.py +178 -0
- accrue-1.0.0/accrue/core/checkpoint.py +184 -0
- accrue-1.0.0/accrue/core/config.py +169 -0
- accrue-1.0.0/accrue/core/enricher.py +213 -0
- accrue-1.0.0/accrue/core/exceptions.py +101 -0
- accrue-1.0.0/accrue/core/hooks.py +114 -0
- accrue-1.0.0/accrue/data/__init__.py +7 -0
- accrue-1.0.0/accrue/data/fields.py +229 -0
- accrue-1.0.0/accrue/pipeline/__init__.py +5 -0
- accrue-1.0.0/accrue/pipeline/pipeline.py +1192 -0
- accrue-1.0.0/accrue/providers.py +22 -0
- accrue-1.0.0/accrue/py.typed +0 -0
- accrue-1.0.0/accrue/schemas/__init__.py +16 -0
- accrue-1.0.0/accrue/schemas/base.py +68 -0
- accrue-1.0.0/accrue/schemas/enrichment.py +13 -0
- accrue-1.0.0/accrue/schemas/field_spec.py +40 -0
- accrue-1.0.0/accrue/schemas/grounding.py +67 -0
- accrue-1.0.0/accrue/steps/__init__.py +13 -0
- accrue-1.0.0/accrue/steps/base.py +69 -0
- accrue-1.0.0/accrue/steps/function.py +83 -0
- accrue-1.0.0/accrue/steps/llm.py +612 -0
- accrue-1.0.0/accrue/steps/prompt_builder.py +258 -0
- accrue-1.0.0/accrue/steps/providers/__init__.py +13 -0
- accrue-1.0.0/accrue/steps/providers/anthropic.py +388 -0
- accrue-1.0.0/accrue/steps/providers/base.py +176 -0
- accrue-1.0.0/accrue/steps/providers/google.py +195 -0
- accrue-1.0.0/accrue/steps/providers/openai.py +580 -0
- accrue-1.0.0/accrue/steps/schema_builder.py +105 -0
- accrue-1.0.0/accrue/utils/__init__.py +5 -0
- accrue-1.0.0/accrue/utils/logger.py +162 -0
- accrue-1.0.0/accrue/utils/web_search.py +140 -0
- accrue-1.0.0/examples/README.md +25 -0
- accrue-1.0.0/pyproject.toml +109 -0
accrue-1.0.0/.gitignore
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
# Byte-compiled / optimized
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*$py.class
|
|
5
|
+
*.so
|
|
6
|
+
|
|
7
|
+
# Distribution / packaging
|
|
8
|
+
.Python
|
|
9
|
+
build/
|
|
10
|
+
dist/
|
|
11
|
+
develop-eggs/
|
|
12
|
+
downloads/
|
|
13
|
+
eggs/
|
|
14
|
+
.eggs/
|
|
15
|
+
sdist/
|
|
16
|
+
var/
|
|
17
|
+
wheels/
|
|
18
|
+
share/python-wheels/
|
|
19
|
+
*.egg-info/
|
|
20
|
+
.installed.cfg
|
|
21
|
+
*.egg
|
|
22
|
+
MANIFEST
|
|
23
|
+
|
|
24
|
+
# Installer logs
|
|
25
|
+
pip-log.txt
|
|
26
|
+
pip-delete-this-directory.txt
|
|
27
|
+
|
|
28
|
+
# Unit test / coverage
|
|
29
|
+
htmlcov/
|
|
30
|
+
.tox/
|
|
31
|
+
.nox/
|
|
32
|
+
.coverage
|
|
33
|
+
.coverage.*
|
|
34
|
+
.cache
|
|
35
|
+
nosetests.xml
|
|
36
|
+
coverage.xml
|
|
37
|
+
*.cover
|
|
38
|
+
*.py,cover
|
|
39
|
+
.hypothesis/
|
|
40
|
+
.pytest_cache/
|
|
41
|
+
cover/
|
|
42
|
+
test_results/
|
|
43
|
+
|
|
44
|
+
# Environments
|
|
45
|
+
.env
|
|
46
|
+
.envrc
|
|
47
|
+
.venv
|
|
48
|
+
env/
|
|
49
|
+
venv/
|
|
50
|
+
ENV/
|
|
51
|
+
env.bak/
|
|
52
|
+
venv.bak/
|
|
53
|
+
.env.local
|
|
54
|
+
.env.*.local
|
|
55
|
+
|
|
56
|
+
# Type checkers
|
|
57
|
+
.mypy_cache/
|
|
58
|
+
.dmypy.json
|
|
59
|
+
dmypy.json
|
|
60
|
+
.pyre/
|
|
61
|
+
.pytype/
|
|
62
|
+
|
|
63
|
+
# Linters / formatters
|
|
64
|
+
.ruff_cache/
|
|
65
|
+
|
|
66
|
+
# Jupyter
|
|
67
|
+
.ipynb_checkpoints/
|
|
68
|
+
|
|
69
|
+
# IPython
|
|
70
|
+
profile_default/
|
|
71
|
+
ipython_config.py
|
|
72
|
+
|
|
73
|
+
# Sphinx docs
|
|
74
|
+
docs/_build/
|
|
75
|
+
|
|
76
|
+
# mkdocs
|
|
77
|
+
/site
|
|
78
|
+
|
|
79
|
+
# PyPI
|
|
80
|
+
.pypirc
|
|
81
|
+
|
|
82
|
+
# IDE / editors
|
|
83
|
+
.idea/
|
|
84
|
+
.vscode/
|
|
85
|
+
*.code-workspace
|
|
86
|
+
*.swp
|
|
87
|
+
*.swo
|
|
88
|
+
|
|
89
|
+
# OS files
|
|
90
|
+
.DS_Store
|
|
91
|
+
Thumbs.db
|
|
92
|
+
ehthumbs.db
|
|
93
|
+
Desktop.ini
|
|
94
|
+
*~
|
|
95
|
+
|
|
96
|
+
# Cython debug
|
|
97
|
+
cython_debug/
|
|
98
|
+
|
|
99
|
+
# Temporary files
|
|
100
|
+
*.tmp
|
|
101
|
+
*.temp
|
|
102
|
+
|
|
103
|
+
# Accrue project-specific
|
|
104
|
+
.notes/
|
|
105
|
+
.accrue/
|
|
106
|
+
.claude/
|
|
107
|
+
docs/_archive/
|
|
108
|
+
enriched_*.csv
|
|
109
|
+
output_*.csv
|
|
110
|
+
results_*.csv
|
accrue-1.0.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Matthew House
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
accrue-1.0.0/PKG-INFO
ADDED
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: accrue
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: A composable pipeline engine for structured data enrichment using LLMs
|
|
5
|
+
Project-URL: Homepage, https://github.com/matt-house-e/accrue
|
|
6
|
+
Project-URL: Bug Reports, https://github.com/matt-house-e/accrue/issues
|
|
7
|
+
Project-URL: Source, https://github.com/matt-house-e/accrue
|
|
8
|
+
Project-URL: Documentation, https://github.com/matt-house-e/accrue#readme
|
|
9
|
+
Author-email: Matthew House <matt.house.e@gmail.com>
|
|
10
|
+
License-Expression: MIT
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
15
|
+
Classifier: Operating System :: OS Independent
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
21
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
22
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
23
|
+
Requires-Python: >=3.10
|
|
24
|
+
Requires-Dist: openai>=1.66.0
|
|
25
|
+
Requires-Dist: pandas>=2.0.0
|
|
26
|
+
Requires-Dist: pydantic>=2.0.0
|
|
27
|
+
Requires-Dist: python-dotenv>=1.0.0
|
|
28
|
+
Requires-Dist: tqdm>=4.65.0
|
|
29
|
+
Provides-Extra: all
|
|
30
|
+
Requires-Dist: anthropic>=0.40.0; extra == 'all'
|
|
31
|
+
Requires-Dist: google-genai>=1.0.0; extra == 'all'
|
|
32
|
+
Requires-Dist: ipykernel>=6.0; extra == 'all'
|
|
33
|
+
Requires-Dist: pre-commit>=4.0; extra == 'all'
|
|
34
|
+
Requires-Dist: pytest-asyncio>=0.25.0; extra == 'all'
|
|
35
|
+
Requires-Dist: pytest-mock>=3.10; extra == 'all'
|
|
36
|
+
Requires-Dist: pytest>=7.0; extra == 'all'
|
|
37
|
+
Requires-Dist: ruff>=0.14.0; extra == 'all'
|
|
38
|
+
Provides-Extra: anthropic
|
|
39
|
+
Requires-Dist: anthropic>=0.40.0; extra == 'anthropic'
|
|
40
|
+
Provides-Extra: dev
|
|
41
|
+
Requires-Dist: ipykernel>=6.0; extra == 'dev'
|
|
42
|
+
Requires-Dist: pre-commit>=4.0; extra == 'dev'
|
|
43
|
+
Requires-Dist: pytest-asyncio>=0.25.0; extra == 'dev'
|
|
44
|
+
Requires-Dist: pytest-mock>=3.10; extra == 'dev'
|
|
45
|
+
Requires-Dist: pytest>=7.0; extra == 'dev'
|
|
46
|
+
Requires-Dist: ruff>=0.14.0; extra == 'dev'
|
|
47
|
+
Provides-Extra: google
|
|
48
|
+
Requires-Dist: google-genai>=1.0.0; extra == 'google'
|
|
49
|
+
Description-Content-Type: text/markdown
|
|
50
|
+
|
|
51
|
+
<p align="center">
|
|
52
|
+
<strong>Accrue</strong><br>
|
|
53
|
+
<em>The enrichment pipeline engine.</em>
|
|
54
|
+
</p>
|
|
55
|
+
|
|
56
|
+
<p align="center">
|
|
57
|
+
<a href="https://pypi.org/project/accrue/"><img src="https://img.shields.io/pypi/v/accrue?color=blue" alt="PyPI"></a>
|
|
58
|
+
<a href="https://pypi.org/project/accrue/"><img src="https://img.shields.io/pypi/pyversions/accrue" alt="Python"></a>
|
|
59
|
+
<a href="https://github.com/matt-house-e/accrue/blob/main/LICENSE"><img src="https://img.shields.io/github/license/matt-house-e/accrue" alt="License"></a>
|
|
60
|
+
</p>
|
|
61
|
+
|
|
62
|
+
---
|
|
63
|
+
|
|
64
|
+
**Define a pipeline. Point it at your data. Get structured results.** Accrue is a Python library for enriching datasets with LLMs. Compose multi-step pipelines, run them across hundreds to tens of thousands of rows, and get validated, structured output back -- with caching, retries, and parallel execution handled for you.
|
|
65
|
+
|
|
66
|
+
No platform. No markup. Just a pipeline you can version-control, iterate on, and reason about.
|
|
67
|
+
|
|
68
|
+
```python
|
|
69
|
+
from accrue import Pipeline, LLMStep
|
|
70
|
+
|
|
71
|
+
pipeline = Pipeline([
|
|
72
|
+
LLMStep("analyze", fields={
|
|
73
|
+
"market_size": "Estimate total addressable market in billions USD",
|
|
74
|
+
"competition": {
|
|
75
|
+
"prompt": "Rate competitive intensity with key competitors",
|
|
76
|
+
"enum": ["Low", "Medium", "High"],
|
|
77
|
+
"examples": ["High - Competes with AWS, Google Cloud"],
|
|
78
|
+
},
|
|
79
|
+
"growth_potential": {
|
|
80
|
+
"prompt": "Assess 5-year growth trajectory",
|
|
81
|
+
"type": "String",
|
|
82
|
+
"format": "X% CAGR - reasoning",
|
|
83
|
+
},
|
|
84
|
+
})
|
|
85
|
+
])
|
|
86
|
+
|
|
87
|
+
result = pipeline.run(df) # DataFrame in, DataFrame out
|
|
88
|
+
print(result.data.head())
|
|
89
|
+
print(f"Tokens used: {result.cost.total_tokens:,}")
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
## Install
|
|
93
|
+
|
|
94
|
+
Requires Python 3.10+.
|
|
95
|
+
|
|
96
|
+
```bash
|
|
97
|
+
pip install accrue
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
Set your API key:
|
|
101
|
+
|
|
102
|
+
```bash
|
|
103
|
+
export OPENAI_API_KEY=sk-...
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
That's it. OpenAI is the default provider (zero config, [structured outputs](https://platform.openai.com/docs/guides/structured-outputs) auto-enabled). Anthropic and Google are optional:
|
|
107
|
+
|
|
108
|
+
```bash
|
|
109
|
+
pip install accrue[anthropic] # Claude
|
|
110
|
+
pip install accrue[google] # Gemini
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
## Why Accrue
|
|
114
|
+
|
|
115
|
+
You have a spreadsheet of companies, leads, or entities. You need structured fields added to every row -- classifications, summaries, scores, extracted data. You could write a `for` loop and call the OpenAI API, but then you're building retry logic, rate limiting, caching, progress tracking, and crash recovery. You could use Clay, but you'd pay $500/month for something you can't version-control.
|
|
116
|
+
|
|
117
|
+
Accrue is the pipeline between a single API call and a full platform:
|
|
118
|
+
|
|
119
|
+
| | Raw API calls | Accrue | Clay |
|
|
120
|
+
|---|---|---|---|
|
|
121
|
+
| **Scope** | One call at a time | Pipeline of steps across rows | Full SaaS platform |
|
|
122
|
+
| **Multi-step** | Manual orchestration | DAG with parallel execution | Sequential drag-and-drop |
|
|
123
|
+
| **Caching** | Build it yourself | SQLite, auto-invalidates on prompt change | Platform-managed |
|
|
124
|
+
| **Crash recovery** | Start over | Checkpoint + row-level cache resume | Platform-managed |
|
|
125
|
+
| **Iterate on prompts** | Re-run everything | Only re-process changed steps/rows | Re-run everything |
|
|
126
|
+
| **Cost** | API costs | API costs | $$$$/month + API costs |
|
|
127
|
+
| **Version control** | Yes | Yes | No |
|
|
128
|
+
|
|
129
|
+
## Quick Example
|
|
130
|
+
|
|
131
|
+
Chain steps together with `depends_on`. Use `web_search()` to ground LLM answers in live data:
|
|
132
|
+
|
|
133
|
+
```python
|
|
134
|
+
from accrue import Pipeline, FunctionStep, LLMStep, web_search
|
|
135
|
+
|
|
136
|
+
pipeline = Pipeline([
|
|
137
|
+
FunctionStep("research",
|
|
138
|
+
fn=web_search("Research {company}: market position, competitors, recent news"),
|
|
139
|
+
fields=["__web_context", "sources"],
|
|
140
|
+
),
|
|
141
|
+
LLMStep("analyze",
|
|
142
|
+
fields={
|
|
143
|
+
"market_size": "Estimate TAM in billions USD",
|
|
144
|
+
"competitors": {"prompt": "List top 3 competitors", "type": "List[String]"},
|
|
145
|
+
"investment_thesis": "One-paragraph investment thesis",
|
|
146
|
+
},
|
|
147
|
+
depends_on=["research"],
|
|
148
|
+
),
|
|
149
|
+
])
|
|
150
|
+
|
|
151
|
+
result = pipeline.run(companies_df)
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
## Features
|
|
155
|
+
|
|
156
|
+
- **Multi-step pipelines** -- Chain LLM steps and function steps into a DAG with automatic dependency resolution and parallel execution. [Quickstart](docs/getting-started/quickstart.md)
|
|
157
|
+
|
|
158
|
+
- **Provider-agnostic** -- OpenAI, Anthropic (with automatic prompt caching), and Google ship as adapters. Any OpenAI-compatible API works via `base_url`. Custom providers implement one async method. [Providers guide](docs/guides/providers.md)
|
|
159
|
+
|
|
160
|
+
- **7-key field specs** -- Control LLM output with `prompt`, `type`, `format`, `enum`, `examples`, `bad_examples`, and `default`. Drives structured outputs and Pydantic validation automatically. [Field specs guide](docs/guides/field-specifications.md)
|
|
161
|
+
|
|
162
|
+
- **Caching and checkpointing** -- SQLite input-hash cache auto-invalidates on prompt changes. Checkpointing saves after each step for crash recovery. [Caching guide](docs/guides/caching.md)
|
|
163
|
+
|
|
164
|
+
- **Batch API** -- `LLMStep(batch=True)` for 50% cost savings via OpenAI and Anthropic batch endpoints. Cache-aware, auto-chunking, realtime fallback on failures. [Batch guide](docs/guides/batch-api.md)
|
|
165
|
+
|
|
166
|
+
- **Web search and grounding** -- `web_search()` factory for search-then-analyze pipelines, or `grounding=True` for native provider web search with normalized citations. [Web search guide](docs/guides/web-search.md)
|
|
167
|
+
|
|
168
|
+
- **Conditional steps** -- `run_if` / `skip_if` predicates for per-row branching. Skipped rows get defaults, never hit the API. [Conditional steps guide](docs/guides/conditional-steps.md)
|
|
169
|
+
|
|
170
|
+
- **Hooks** -- Typed lifecycle events for observability. Sync and async callables, never crash the pipeline. [Hooks guide](docs/guides/hooks.md)
|
|
171
|
+
|
|
172
|
+
- **`provider_kwargs`** -- Escape hatch for provider-specific features (extended thinking, effort control, etc.) without waiting for first-class support.
|
|
173
|
+
|
|
174
|
+
## Sweet Spot
|
|
175
|
+
|
|
176
|
+
Accrue is built for **100 to 50,000 rows** -- too many for manual work or single-call tools, too few to justify big data infrastructure.
|
|
177
|
+
|
|
178
|
+
| Rows | Time (3 steps, 10 workers) | Cost (gpt-4.1-mini) |
|
|
179
|
+
|------|---------------------------|---------------------|
|
|
180
|
+
| 100 | ~30s | ~$0.20 |
|
|
181
|
+
| 1,000 | ~5 min | ~$2 |
|
|
182
|
+
| 10,000 | ~50 min | ~$20 |
|
|
183
|
+
| 50,000 | ~50 min (50 workers) | ~$100 |
|
|
184
|
+
|
|
185
|
+
With `batch=True`, halve the API costs. Cached steps re-run in seconds.
|
|
186
|
+
|
|
187
|
+
## Documentation
|
|
188
|
+
|
|
189
|
+
| Section | Description |
|
|
190
|
+
|---------|-------------|
|
|
191
|
+
| [Getting Started](docs/getting-started/quickstart.md) | Installation, first pipeline, core concepts |
|
|
192
|
+
| [Guides](docs/guides/) | Field specs, providers, caching, batch API, grounding, hooks, errors, configuration |
|
|
193
|
+
| [Cookbook](docs/cookbook/) | End-to-end examples: [company enrichment](docs/cookbook/company-enrichment.md), [lead scoring](docs/cookbook/lead-scoring.md), [content analysis](docs/cookbook/content-analysis.md), [batch processing](docs/cookbook/batch-processing.md) |
|
|
194
|
+
| [API Reference](docs/reference/api.md) | Complete reference for every public export |
|
|
195
|
+
|
|
196
|
+
## Contributing
|
|
197
|
+
|
|
198
|
+
```bash
|
|
199
|
+
git clone https://github.com/matt-house-e/accrue.git
|
|
200
|
+
cd accrue
|
|
201
|
+
pip install -e ".[dev]"
|
|
202
|
+
pytest
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
## License
|
|
206
|
+
|
|
207
|
+
MIT
|
accrue-1.0.0/README.md
ADDED
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<strong>Accrue</strong><br>
|
|
3
|
+
<em>The enrichment pipeline engine.</em>
|
|
4
|
+
</p>
|
|
5
|
+
|
|
6
|
+
<p align="center">
|
|
7
|
+
<a href="https://pypi.org/project/accrue/"><img src="https://img.shields.io/pypi/v/accrue?color=blue" alt="PyPI"></a>
|
|
8
|
+
<a href="https://pypi.org/project/accrue/"><img src="https://img.shields.io/pypi/pyversions/accrue" alt="Python"></a>
|
|
9
|
+
<a href="https://github.com/matt-house-e/accrue/blob/main/LICENSE"><img src="https://img.shields.io/github/license/matt-house-e/accrue" alt="License"></a>
|
|
10
|
+
</p>
|
|
11
|
+
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
**Define a pipeline. Point it at your data. Get structured results.** Accrue is a Python library for enriching datasets with LLMs. Compose multi-step pipelines, run them across hundreds to tens of thousands of rows, and get validated, structured output back -- with caching, retries, and parallel execution handled for you.
|
|
15
|
+
|
|
16
|
+
No platform. No markup. Just a pipeline you can version-control, iterate on, and reason about.
|
|
17
|
+
|
|
18
|
+
```python
|
|
19
|
+
from accrue import Pipeline, LLMStep
|
|
20
|
+
|
|
21
|
+
pipeline = Pipeline([
|
|
22
|
+
LLMStep("analyze", fields={
|
|
23
|
+
"market_size": "Estimate total addressable market in billions USD",
|
|
24
|
+
"competition": {
|
|
25
|
+
"prompt": "Rate competitive intensity with key competitors",
|
|
26
|
+
"enum": ["Low", "Medium", "High"],
|
|
27
|
+
"examples": ["High - Competes with AWS, Google Cloud"],
|
|
28
|
+
},
|
|
29
|
+
"growth_potential": {
|
|
30
|
+
"prompt": "Assess 5-year growth trajectory",
|
|
31
|
+
"type": "String",
|
|
32
|
+
"format": "X% CAGR - reasoning",
|
|
33
|
+
},
|
|
34
|
+
})
|
|
35
|
+
])
|
|
36
|
+
|
|
37
|
+
result = pipeline.run(df) # DataFrame in, DataFrame out
|
|
38
|
+
print(result.data.head())
|
|
39
|
+
print(f"Tokens used: {result.cost.total_tokens:,}")
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## Install
|
|
43
|
+
|
|
44
|
+
Requires Python 3.10+.
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
pip install accrue
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
Set your API key:
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
export OPENAI_API_KEY=sk-...
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
That's it. OpenAI is the default provider (zero config, [structured outputs](https://platform.openai.com/docs/guides/structured-outputs) auto-enabled). Anthropic and Google are optional:
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
pip install accrue[anthropic] # Claude
|
|
60
|
+
pip install accrue[google] # Gemini
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## Why Accrue
|
|
64
|
+
|
|
65
|
+
You have a spreadsheet of companies, leads, or entities. You need structured fields added to every row -- classifications, summaries, scores, extracted data. You could write a `for` loop and call the OpenAI API, but then you're building retry logic, rate limiting, caching, progress tracking, and crash recovery. You could use Clay, but you'd pay $500/month for something you can't version-control.
|
|
66
|
+
|
|
67
|
+
Accrue is the pipeline between a single API call and a full platform:
|
|
68
|
+
|
|
69
|
+
| | Raw API calls | Accrue | Clay |
|
|
70
|
+
|---|---|---|---|
|
|
71
|
+
| **Scope** | One call at a time | Pipeline of steps across rows | Full SaaS platform |
|
|
72
|
+
| **Multi-step** | Manual orchestration | DAG with parallel execution | Sequential drag-and-drop |
|
|
73
|
+
| **Caching** | Build it yourself | SQLite, auto-invalidates on prompt change | Platform-managed |
|
|
74
|
+
| **Crash recovery** | Start over | Checkpoint + row-level cache resume | Platform-managed |
|
|
75
|
+
| **Iterate on prompts** | Re-run everything | Only re-process changed steps/rows | Re-run everything |
|
|
76
|
+
| **Cost** | API costs | API costs | $$$$/month + API costs |
|
|
77
|
+
| **Version control** | Yes | Yes | No |
|
|
78
|
+
|
|
79
|
+
## Quick Example
|
|
80
|
+
|
|
81
|
+
Chain steps together with `depends_on`. Use `web_search()` to ground LLM answers in live data:
|
|
82
|
+
|
|
83
|
+
```python
|
|
84
|
+
from accrue import Pipeline, FunctionStep, LLMStep, web_search
|
|
85
|
+
|
|
86
|
+
pipeline = Pipeline([
|
|
87
|
+
FunctionStep("research",
|
|
88
|
+
fn=web_search("Research {company}: market position, competitors, recent news"),
|
|
89
|
+
fields=["__web_context", "sources"],
|
|
90
|
+
),
|
|
91
|
+
LLMStep("analyze",
|
|
92
|
+
fields={
|
|
93
|
+
"market_size": "Estimate TAM in billions USD",
|
|
94
|
+
"competitors": {"prompt": "List top 3 competitors", "type": "List[String]"},
|
|
95
|
+
"investment_thesis": "One-paragraph investment thesis",
|
|
96
|
+
},
|
|
97
|
+
depends_on=["research"],
|
|
98
|
+
),
|
|
99
|
+
])
|
|
100
|
+
|
|
101
|
+
result = pipeline.run(companies_df)
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
## Features
|
|
105
|
+
|
|
106
|
+
- **Multi-step pipelines** -- Chain LLM steps and function steps into a DAG with automatic dependency resolution and parallel execution. [Quickstart](docs/getting-started/quickstart.md)
|
|
107
|
+
|
|
108
|
+
- **Provider-agnostic** -- OpenAI, Anthropic (with automatic prompt caching), and Google ship as adapters. Any OpenAI-compatible API works via `base_url`. Custom providers implement one async method. [Providers guide](docs/guides/providers.md)
|
|
109
|
+
|
|
110
|
+
- **7-key field specs** -- Control LLM output with `prompt`, `type`, `format`, `enum`, `examples`, `bad_examples`, and `default`. Drives structured outputs and Pydantic validation automatically. [Field specs guide](docs/guides/field-specifications.md)
|
|
111
|
+
|
|
112
|
+
- **Caching and checkpointing** -- SQLite input-hash cache auto-invalidates on prompt changes. Checkpointing saves after each step for crash recovery. [Caching guide](docs/guides/caching.md)
|
|
113
|
+
|
|
114
|
+
- **Batch API** -- `LLMStep(batch=True)` for 50% cost savings via OpenAI and Anthropic batch endpoints. Cache-aware, auto-chunking, realtime fallback on failures. [Batch guide](docs/guides/batch-api.md)
|
|
115
|
+
|
|
116
|
+
- **Web search and grounding** -- `web_search()` factory for search-then-analyze pipelines, or `grounding=True` for native provider web search with normalized citations. [Web search guide](docs/guides/web-search.md)
|
|
117
|
+
|
|
118
|
+
- **Conditional steps** -- `run_if` / `skip_if` predicates for per-row branching. Skipped rows get defaults, never hit the API. [Conditional steps guide](docs/guides/conditional-steps.md)
|
|
119
|
+
|
|
120
|
+
- **Hooks** -- Typed lifecycle events for observability. Sync and async callables, never crash the pipeline. [Hooks guide](docs/guides/hooks.md)
|
|
121
|
+
|
|
122
|
+
- **`provider_kwargs`** -- Escape hatch for provider-specific features (extended thinking, effort control, etc.) without waiting for first-class support.
|
|
123
|
+
|
|
124
|
+
## Sweet Spot
|
|
125
|
+
|
|
126
|
+
Accrue is built for **100 to 50,000 rows** -- too many for manual work or single-call tools, too few to justify big data infrastructure.
|
|
127
|
+
|
|
128
|
+
| Rows | Time (3 steps, 10 workers) | Cost (gpt-4.1-mini) |
|
|
129
|
+
|------|---------------------------|---------------------|
|
|
130
|
+
| 100 | ~30s | ~$0.20 |
|
|
131
|
+
| 1,000 | ~5 min | ~$2 |
|
|
132
|
+
| 10,000 | ~50 min | ~$20 |
|
|
133
|
+
| 50,000 | ~50 min (50 workers) | ~$100 |
|
|
134
|
+
|
|
135
|
+
With `batch=True`, halve the API costs. Cached steps re-run in seconds.
|
|
136
|
+
|
|
137
|
+
## Documentation
|
|
138
|
+
|
|
139
|
+
| Section | Description |
|
|
140
|
+
|---------|-------------|
|
|
141
|
+
| [Getting Started](docs/getting-started/quickstart.md) | Installation, first pipeline, core concepts |
|
|
142
|
+
| [Guides](docs/guides/) | Field specs, providers, caching, batch API, grounding, hooks, errors, configuration |
|
|
143
|
+
| [Cookbook](docs/cookbook/) | End-to-end examples: [company enrichment](docs/cookbook/company-enrichment.md), [lead scoring](docs/cookbook/lead-scoring.md), [content analysis](docs/cookbook/content-analysis.md), [batch processing](docs/cookbook/batch-processing.md) |
|
|
144
|
+
| [API Reference](docs/reference/api.md) | Complete reference for every public export |
|
|
145
|
+
|
|
146
|
+
## Contributing
|
|
147
|
+
|
|
148
|
+
```bash
|
|
149
|
+
git clone https://github.com/matt-house-e/accrue.git
|
|
150
|
+
cd accrue
|
|
151
|
+
pip install -e ".[dev]"
|
|
152
|
+
pytest
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
## License
|
|
156
|
+
|
|
157
|
+
MIT
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"""Accrue — Enrichment Pipeline Engine.
|
|
2
|
+
|
|
3
|
+
A programmatic enrichment engine built on composable, column-oriented
|
|
4
|
+
pipeline steps with Pydantic validation, checkpointing, and async concurrency.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
# Set up default logging when package is imported
|
|
8
|
+
from .utils.logger import setup_logging
|
|
9
|
+
|
|
10
|
+
setup_logging(level="WARNING", format_type="console", include_timestamp=False)
|
|
11
|
+
|
|
12
|
+
# Public API
|
|
13
|
+
from .core import (
|
|
14
|
+
Enricher,
|
|
15
|
+
EnrichmentConfig,
|
|
16
|
+
EnrichmentError,
|
|
17
|
+
FieldValidationError,
|
|
18
|
+
PipelineError,
|
|
19
|
+
RowError,
|
|
20
|
+
StepError,
|
|
21
|
+
)
|
|
22
|
+
from .core.hooks import (
|
|
23
|
+
EnrichmentHooks,
|
|
24
|
+
PipelineEndEvent,
|
|
25
|
+
PipelineStartEvent,
|
|
26
|
+
RowCompleteEvent,
|
|
27
|
+
StepEndEvent,
|
|
28
|
+
StepStartEvent,
|
|
29
|
+
)
|
|
30
|
+
from .pipeline import Pipeline, PipelineResult
|
|
31
|
+
from .schemas.base import CostSummary
|
|
32
|
+
from .schemas.field_spec import FieldSpec
|
|
33
|
+
from .schemas.grounding import GroundingConfig
|
|
34
|
+
from .steps import FunctionStep, LLMStep, Step, StepContext, StepResult
|
|
35
|
+
from .steps.providers.base import BatchCapableLLMClient, BatchRequest, BatchResult
|
|
36
|
+
from .utils.web_search import web_search
|
|
37
|
+
|
|
38
|
+
__version__ = "1.0.0"
|
|
39
|
+
__author__ = "Accrue Team"
|
|
40
|
+
|
|
41
|
+
__all__ = [
|
|
42
|
+
# Primary API
|
|
43
|
+
"Pipeline",
|
|
44
|
+
"PipelineResult",
|
|
45
|
+
"LLMStep",
|
|
46
|
+
"FunctionStep",
|
|
47
|
+
"EnrichmentConfig",
|
|
48
|
+
# Hooks
|
|
49
|
+
"EnrichmentHooks",
|
|
50
|
+
"PipelineStartEvent",
|
|
51
|
+
"PipelineEndEvent",
|
|
52
|
+
"StepStartEvent",
|
|
53
|
+
"StepEndEvent",
|
|
54
|
+
"RowCompleteEvent",
|
|
55
|
+
# Step protocol
|
|
56
|
+
"Step",
|
|
57
|
+
"StepContext",
|
|
58
|
+
"StepResult",
|
|
59
|
+
# Schemas
|
|
60
|
+
"FieldSpec",
|
|
61
|
+
"GroundingConfig",
|
|
62
|
+
# Utilities
|
|
63
|
+
"web_search",
|
|
64
|
+
# Batch API
|
|
65
|
+
"BatchCapableLLMClient",
|
|
66
|
+
"BatchRequest",
|
|
67
|
+
"BatchResult",
|
|
68
|
+
# Results & errors
|
|
69
|
+
"CostSummary",
|
|
70
|
+
"RowError",
|
|
71
|
+
"EnrichmentError",
|
|
72
|
+
"FieldValidationError",
|
|
73
|
+
"StepError",
|
|
74
|
+
"PipelineError",
|
|
75
|
+
# Internal runner (power users)
|
|
76
|
+
"Enricher",
|
|
77
|
+
]
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"""Core functionality for the Accrue enrichment tool."""
|
|
2
|
+
|
|
3
|
+
from .cache import CacheManager
|
|
4
|
+
from .checkpoint import CheckpointData, CheckpointManager
|
|
5
|
+
from .config import EnrichmentConfig
|
|
6
|
+
from .enricher import Enricher
|
|
7
|
+
from .exceptions import (
|
|
8
|
+
EnrichmentError,
|
|
9
|
+
FieldValidationError,
|
|
10
|
+
PipelineError,
|
|
11
|
+
RowError,
|
|
12
|
+
StepError,
|
|
13
|
+
)
|
|
14
|
+
from .hooks import (
|
|
15
|
+
EnrichmentHooks,
|
|
16
|
+
PipelineEndEvent,
|
|
17
|
+
PipelineStartEvent,
|
|
18
|
+
RowCompleteEvent,
|
|
19
|
+
StepEndEvent,
|
|
20
|
+
StepStartEvent,
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
__all__ = [
|
|
24
|
+
"CacheManager",
|
|
25
|
+
"Enricher",
|
|
26
|
+
"CheckpointManager",
|
|
27
|
+
"CheckpointData",
|
|
28
|
+
"EnrichmentConfig",
|
|
29
|
+
"EnrichmentError",
|
|
30
|
+
"FieldValidationError",
|
|
31
|
+
"StepError",
|
|
32
|
+
"PipelineError",
|
|
33
|
+
"RowError",
|
|
34
|
+
"EnrichmentHooks",
|
|
35
|
+
"PipelineStartEvent",
|
|
36
|
+
"PipelineEndEvent",
|
|
37
|
+
"StepStartEvent",
|
|
38
|
+
"StepEndEvent",
|
|
39
|
+
"RowCompleteEvent",
|
|
40
|
+
]
|