Composable block-based Python component architecture framework
Project description
pylego
레고처럼 조립 가능한 파이썬 컴포넌트 아키텍처 프레임워크. 작은 표준 블록(Block)을 pydantic v2 계약(Stud)으로 스냅해 Assembly로 조립한다.
설치
pip install pylego-blocks
uv 사용 시:
uv add pylego-blocks
선택적 의존성 설치:
pip install pylego-blocks[anthropic] # Claude API
pip install pylego-blocks[openai] # OpenAI API
pip install pylego-blocks[serve] # FastAPI HTTP 서빙
pip install pylego-blocks[all] # 전체
빠른 시작
1. Block 정의
from pylego_blocks.core.block import Block
from pylego_blocks.core.stud import Stud
class TextInput(Stud):
text: str
class UpperOutput(Stud):
text: str
class LengthOutput(Stud):
length: int
class UpperBlock(Block[TextInput, UpperOutput]):
input_model = TextInput
output_model = UpperOutput
async def run(self, inp: TextInput) -> UpperOutput:
return UpperOutput(text=inp.text.upper())
class LengthBlock(Block[UpperOutput, LengthOutput]):
input_model = UpperOutput
output_model = LengthOutput
async def run(self, inp: UpperOutput) -> LengthOutput:
return LengthOutput(length=len(inp.text))
2. Assembly 조립 및 실행
from pylego_blocks.core.assembly import Assembly
# 조립 시점에 Stud 계약 불일치를 즉시 검출
pipeline = Assembly([UpperBlock(), LengthBlock()])
# 비동기
import asyncio
result = asyncio.run(pipeline.run(TextInput(text="hello")))
# 동기 편의 API
result = pipeline.run_sync(TextInput(text="hello"))
print(result.length) # 5
3. YAML 선언형 조립
# pipeline.yaml
name: text-pipeline
blocks:
- class: myapp.blocks.UpperBlock
- class: myapp.blocks.LengthBlock
from pylego_blocks.declarative import load_assembly
pipeline = load_assembly("pipeline.yaml")
result = pipeline.run_sync(TextInput(text="hello"))
4. FanOut — 동시 분기 실행
from pylego_blocks.core.fanout import FanOut, Gathered
fan = FanOut([UpperBlock(), LengthBlock()])
# 두 브랜치를 asyncio.gather 로 동시 실행 → Gathered(results=(…, …))
result: Gathered = asyncio.run(fan.run(TextInput(text="hello")))
5. BlockRegistry
from pylego_blocks.registry import register, default_registry
@register
class UpperBlock(Block[TextInput, UpperOutput]):
...
cls = default_registry.get("UpperBlock")
핵심 원칙
- 블록은 다른 블록 내부를 모른다 — Stud(계약)만 안다.
- 블록은 단독 실행·단독 테스트가 가능해야 한다.
- Assembly는 블록과 구분 불가능해야 한다 (재귀적 합성).
- 런타임 교체(sync↔async)가 블록 수정 없이 가능해야 한다.
개발 환경
# 의존성 설치
uv sync
# 테스트
uv run pytest
# 타입 체크
uv run mypy src/
# 빌드
uv build
문서
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pylego_blocks-0.1.9.tar.gz.
File metadata
- Download URL: pylego_blocks-0.1.9.tar.gz
- Upload date:
- Size: 443.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8ef568fac25416a2fec76a3e6514ae75ccb247043f8c5c0a1d76365beb310c9d
|
|
| MD5 |
9d47913cdc7b1a05ca9c4c897be59e06
|
|
| BLAKE2b-256 |
eabc498a56ab3482d9e7b59d5be808f831d11b4da1521549a6e9697e3d1b1b50
|
Provenance
The following attestation bundles were made for pylego_blocks-0.1.9.tar.gz:
Publisher:
publish.yml on hoksi/pylego
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pylego_blocks-0.1.9.tar.gz -
Subject digest:
8ef568fac25416a2fec76a3e6514ae75ccb247043f8c5c0a1d76365beb310c9d - Sigstore transparency entry: 1399511990
- Sigstore integration time:
-
Permalink:
hoksi/pylego@8b1d7ae26a9bbfd67abfffc46b645fec69691b3e -
Branch / Tag:
refs/tags/v0.1.9 - Owner: https://github.com/hoksi
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@8b1d7ae26a9bbfd67abfffc46b645fec69691b3e -
Trigger Event:
push
-
Statement type:
File details
Details for the file pylego_blocks-0.1.9-py3-none-any.whl.
File metadata
- Download URL: pylego_blocks-0.1.9-py3-none-any.whl
- Upload date:
- Size: 174.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4df29f820061079799dfb9759f9e8861237ef63bd611bd6aa310d4484d6b4096
|
|
| MD5 |
bb3eb50257d19d36c137cf193ac58532
|
|
| BLAKE2b-256 |
99f82a55e222964717465376262092e71e695d8e2b149a023514dab634d5f786
|
Provenance
The following attestation bundles were made for pylego_blocks-0.1.9-py3-none-any.whl:
Publisher:
publish.yml on hoksi/pylego
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pylego_blocks-0.1.9-py3-none-any.whl -
Subject digest:
4df29f820061079799dfb9759f9e8861237ef63bd611bd6aa310d4484d6b4096 - Sigstore transparency entry: 1399512001
- Sigstore integration time:
-
Permalink:
hoksi/pylego@8b1d7ae26a9bbfd67abfffc46b645fec69691b3e -
Branch / Tag:
refs/tags/v0.1.9 - Owner: https://github.com/hoksi
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@8b1d7ae26a9bbfd67abfffc46b645fec69691b3e -
Trigger Event:
push
-
Statement type: