Skip to main content

Schema-driven module development framework for AI-perceivable interfaces

Project description

apcore logo

apcore

Schema-driven module development framework for AI-perceivable interfaces.

apcore provides a unified task orchestration framework with strict type safety, access control, middleware pipelines, and built-in observability. It enables you to define modules with structured input/output schemas that are easily consumed by LLMs and other automated systems.

Features

  • Schema-driven modules -- Define input/output contracts using Pydantic models with automatic validation
  • 10-step execution pipeline -- Context creation, safety checks, ACL enforcement, validation, middleware chains, and execution with timeout support
  • @module decorator -- Turn plain functions into fully schema-aware modules with zero boilerplate
  • YAML bindings -- Register modules declaratively without modifying source code
  • Access control (ACL) -- Pattern-based, first-match-wins rules with wildcard support
  • Middleware system -- Composable before/after hooks with error recovery
  • Observability -- Tracing (spans), metrics collection, and structured context logging
  • Async support -- Seamless sync and async module execution
  • Safety guards -- Call depth limits, circular call detection, frequency throttling

Requirements

  • Python >= 3.11

Installation

pip install -e .

For development:

pip install -e ".[dev]"

Quick Start

Define a module with the decorator

from apcore import module

@module(description="Add two integers", tags=["math"])
def add(a: int, b: int) -> int:
    return a + b

Define a module with a class

from pydantic import BaseModel
from apcore import Context

class GreetInput(BaseModel):
    name: str

class GreetOutput(BaseModel):
    message: str

class GreetModule:
    input_schema = GreetInput
    output_schema = GreetOutput
    description = "Greet a user"

    def execute(self, inputs: dict, context: Context) -> dict:
        return {"message": f"Hello, {inputs['name']}!"}

Register and execute

from apcore import Registry, Executor

registry = Registry()
registry.register("greet", GreetModule())

executor = Executor(registry=registry)
result = executor.call("greet", {"name": "Alice"})
# {"message": "Hello, Alice!"}

Add middleware

from apcore import LoggingMiddleware, TracingMiddleware

executor.use(LoggingMiddleware())
executor.use(TracingMiddleware())

Access control

from apcore import ACL, ACLRule

acl = ACL(rules=[
    ACLRule(callers=["admin.*"], targets=["*"], effect="allow", description="Admins can call anything"),
    ACLRule(callers=["*"], targets=["admin.*"], effect="deny", description="Others cannot call admin modules"),
])
executor = Executor(registry=registry, acl=acl)

Project Structure

src/apcore/
    __init__.py          # Public API
    context.py           # Execution context & identity
    executor.py          # Core execution engine
    decorator.py         # @module decorator
    bindings.py          # YAML binding loader
    config.py            # Configuration
    acl.py               # Access control
    errors.py            # Error hierarchy
    module.py            # Module annotations & metadata
    middleware/           # Middleware system
    observability/       # Tracing, metrics, logging
    registry/            # Module discovery & registration
    schema/              # Schema loading, validation, export
    utils/               # Utilities

Development

Run tests

pytest

Run tests with coverage

pytest --cov=src/apcore --cov-report=html

Lint and format

ruff check --fix src/ tests/
ruff format src/ tests/

Type check

mypy src/ tests/

📄 License

Apache-2.0

🔗 Links

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

apcore-0.4.0.tar.gz (80.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

apcore-0.4.0-py3-none-any.whl (63.0 kB view details)

Uploaded Python 3

File details

Details for the file apcore-0.4.0.tar.gz.

File metadata

  • Download URL: apcore-0.4.0.tar.gz
  • Upload date:
  • Size: 80.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for apcore-0.4.0.tar.gz
Algorithm Hash digest
SHA256 bbf4d8c5dca3d486f8111949e6d1f8013bc53653f711f655153fec77b9cb7790
MD5 fa7d0a5f576989f37a79466beadde1b9
BLAKE2b-256 6f0c6d057d9d2950ff86433e5e908f7bf28f45ca4022c25e9f7f24c521ee12c0

See more details on using hashes here.

File details

Details for the file apcore-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: apcore-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 63.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for apcore-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 91cc9b4202dc09f43b7cc9a78a1f8c66956b025357bc34922048ca76d32b7ade
MD5 814ab0d9ef917526b308d6acd936789f
BLAKE2b-256 19f531db549c9003682221d02ee84834910da9281a04cec553b5f8106da082bc

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page