Skip to main content

Shared scanner, schema extraction, and output toolkit for apcore framework adapters

Project description

apcore-toolkit logo

apcore-toolkit-python

Python implementation of the apcore-toolkit.

Extracts ~1,400 lines of duplicated framework-agnostic logic from django-apcore and flask-apcore into a standalone Python package.

Installation

pip install apcore-toolkit

Core Modules

Module Description
ScannedModule Canonical dataclass representing a scanned endpoint
BaseScanner Abstract base class for framework scanners with filtering and deduplication
YAMLWriter Generates .binding.yaml files for apcore.BindingLoader
PythonWriter Generates @module-decorated Python wrapper files
RegistryWriter Registers modules directly into an apcore.Registry
AIEnhancer SLM-based metadata enhancement for scanned modules
WriteResult Structured result type for all writer operations
WriteError Error class for I/O failures during write
Verifier Pluggable protocol for validating written artifacts
VerifyResult Result type for verification operations
YAMLVerifier Verifies YAML files parse correctly with required fields
SyntaxVerifier Verifies source files are non-empty and readable
RegistryVerifier Verifies modules are registered and retrievable
MagicBytesVerifier Verifies file headers match expected magic bytes
JSONVerifier Verifies JSON files parse correctly
to_markdown Converts arbitrary dicts to Markdown with depth control and table heuristics
flatten_pydantic_params Converts Pydantic model parameters to flat kwargs
resolve_target Resolves "module.path:function_name" to callable
enrich_schema_descriptions Merges descriptions into JSON Schema properties
get_writer Factory function for writer instances

Usage

Scanning and Writing

from apcore_toolkit import BaseScanner, ScannedModule, YAMLWriter

class MyScanner(BaseScanner):
    def scan(self, **kwargs):
        # Scan your framework endpoints and return ScannedModule instances
        return [
            ScannedModule(
                module_id="users.get_user",
                description="Get a user by ID",
                input_schema={"type": "object", "properties": {"id": {"type": "integer"}}, "required": ["id"]},
                output_schema={"type": "object", "properties": {"name": {"type": "string"}}},
                tags=["users"],
                target="myapp.views:get_user",
            )
        ]

    def get_source_name(self):
        return "my-framework"

scanner = MyScanner()
modules = scanner.scan()

# Filter and deduplicate
modules = scanner.filter_modules(modules, include=r"^users\.")
modules = scanner.deduplicate_ids(modules)

# Write YAML binding files
writer = YAMLWriter()
writer.write(modules, output_dir="./bindings")

Direct Registry Registration

from apcore import Registry
from apcore_toolkit import RegistryWriter

registry = Registry()
writer = RegistryWriter()
writer.write(modules, registry)

Output Format Factory

from apcore_toolkit.output import get_writer

writer = get_writer("yaml")    # YAMLWriter
writer = get_writer("python")  # PythonWriter
writer = get_writer("registry")  # RegistryWriter

Pydantic Model Flattening

from apcore_toolkit import flatten_pydantic_params, resolve_target

# Resolve a target string to a callable
func = resolve_target("myapp.views:create_task")

# Flatten Pydantic model params into scalar kwargs for MCP tools
wrapped = flatten_pydantic_params(func)

OpenAPI Schema Extraction

from apcore_toolkit.openapi import extract_input_schema, extract_output_schema

input_schema = extract_input_schema(operation, openapi_doc)
output_schema = extract_output_schema(operation, openapi_doc)

Schema Enrichment

from apcore_toolkit import enrich_schema_descriptions

enriched = enrich_schema_descriptions(schema, {"user_id": "The user ID"})

Markdown Formatting

from apcore_toolkit import to_markdown

md = to_markdown({"name": "Alice", "role": "admin"}, title="User Info")

Requirements

  • Python >= 3.11
  • apcore >= 0.13.0
  • pydantic >= 2.0
  • PyYAML >= 6.0

Documentation

Full documentation is available at https://github.com/aipartnerup/apcore-toolkit.

License

Apache-2.0

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_toolkit-0.2.0.tar.gz (38.3 kB view details)

Uploaded Source

Built Distribution

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

apcore_toolkit-0.2.0-py3-none-any.whl (28.5 kB view details)

Uploaded Python 3

File details

Details for the file apcore_toolkit-0.2.0.tar.gz.

File metadata

  • Download URL: apcore_toolkit-0.2.0.tar.gz
  • Upload date:
  • Size: 38.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.11

File hashes

Hashes for apcore_toolkit-0.2.0.tar.gz
Algorithm Hash digest
SHA256 9c88312d8f556ded45c4d369bf8eb34551aaecc503bcc3930c47ae7d94ded64e
MD5 8ab80a8cd1829022314a53b43064315e
BLAKE2b-256 53801ace8443455d61506ddbead4d230be0518d5c1d84bb8d13895cfc178141a

See more details on using hashes here.

File details

Details for the file apcore_toolkit-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: apcore_toolkit-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 28.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.11

File hashes

Hashes for apcore_toolkit-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 45e7bbce4d41771dc776eaba38ef10ed05fa3b2756ed07272de89b973dfd17c8
MD5 e64dd997664194e8519a65d61e95133d
BLAKE2b-256 fe8db7221d5f5c93e0c8a262bb779add244a867660e8b2f23efbfa73b777a154

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