Skip to main content

Service Dock: scaffold APIs from OpenAPI, record/replay responses, and enforce runtime contracts & policies.

Project description

๐Ÿ›ก๏ธ Service Dock

Scaffold APIs from OpenAPI, record/replay responses, and enforce runtime contracts & policies.

Python 3.8+


๐ŸŽฏ What is This?

Service Agent Stack validates API responses at runtime, enforces policies (PII protection, field filtering), and enables contract testing through recording/replay - all without code generation.

Think of it as: Runtime safety for APIs that OpenAPI CodeGen can't provide.


โšก Quick Start

Option A: Install from PyPI (recommended)

pip install servicedock

servicedock setup

Then follow the prompts: enter your OpenAPI spec URL (or path), choose an API name, optionally record GET endpoints, and generate a FastAPI service shell. Run with uvicorn services.<name>_service:app --reload; use SERVICE_AGENT_MODE=replay for local playback.

Option B: From source (this repo)

pip install -r requirements.txt
python3 agentstack.py setup

Manual steps are still available:

  1. Scaffold โ€” servicedock init --api dogapi (or --api myapi --url https://...)
  2. Call & record โ€” servicedock call breed.breed.images.random.get --breed husky
  3. Test โ€” PYTHONPATH=. python3 tests/test_contract_dog_api.py --mode replay

๐Ÿ“‹ Workflow at a glance

Step What you do Command
0 Guided flow (spec โ†’ record โ†’ service) servicedock setup
1 Clone/add an API from its OpenAPI spec servicedock init --api <name> or servicedock init --api <name> --url <spec_url>
2 See endpoints ls scaffolds/
3 Record live responses for replay servicedock call <endpoint> --param value ...
4 Use in code agent.api("ApiName").get("<endpoint>", params) with @contract
5 Run contract tests (replay = no network) PYTHONPATH=. python3 tests/test_contract_*.py --mode replay
6 Run your service (live or replay) uvicorn ... โ€” set SERVICE_AGENT_MODE=replay to use recordings

Full walkthrough: USER_WORKFLOW.md.


๐ŸŒŸ Key Features

โœ… Runtime Contract Validation

Ensure APIs actually return what you expect, not just type correctness.

@contract({
    "expects": {
        "message": "must_be_non_empty_string",
        "status": "must_be_non_empty_string"
    }
})
def fetch_dog_image(breed: str):
    return agent.api("DogAPI").get("breed.breed.images.random.get", {"breed": breed})

๐Ÿ”’ PII Protection

Automatically detect and sanitize PII fields (GDPR compliance helper).

@contract({
    "policy": {
        "no_PII": True,
        "sanitize_PII": True  # Redacts email, phone, etc.
    }
})

๐ŸŽฏ Field Filtering

Strip unnecessary fields before sending to clients.

@contract({
    "only_allow": ["id", "name"]  # Filter everything else
})

๐Ÿ“ผ Recording/Replay

Record live API calls, replay in tests (deterministic, no network).

# Record
python3 agentstack.py call endpoint.name --param value

# Replay in tests
pytest --mode replay

๐Ÿš€ No Code Generation

Point at OpenAPI spec and start validating immediately.


๐Ÿ“– Documentation


๐Ÿ†š vs OpenAPI CodeGen

Feature CodeGen Service Agent Stack
Type Safety โœ… Static โœ… Runtime
Contract Testing โŒ โœ…
PII Protection โŒ โœ…
Recording/Replay โŒ โœ…
Policy Enforcement โŒ โœ…
Code Generation โœ… โŒ (by design)

They're complementary! Use CodeGen for development, Service Agent Stack for runtime safety.


๐ŸŽฌ Demo Example

See the complete Dog CEO API demo:

  1. OpenAPI Spec: service_agent/specs/dogapi.json
  2. Scaffolds: scaffolds/breed.*.get.json
  3. Recordings: recordings/breed.*.json
  4. Contract Tests: tests/test_contract_dog_api.py
  5. Service Example: services/dog_service.py
# Run the full demo
cd /path/to/service-agent-stack

# Make live calls (records responses)
python3 agentstack.py call breeds.list.all.get
python3 agentstack.py call breed.breed.images.random.get --breed husky

# Run contract tests (no network, uses recordings)
PYTHONPATH=. python3 tests/test_contract_dog_api.py --mode replay

# Run the service
uvicorn services.dog_service:app --reload
curl http://localhost:8000/dogs/husky/random-image

๐Ÿ—๏ธ Architecture

service_agent/
โ”œโ”€โ”€ agents/
โ”‚   โ”œโ”€โ”€ schema_agent.py      # OpenAPI spec parsing & scaffolding
โ”‚   โ”œโ”€โ”€ recording_agent.py   # Record API interactions
โ”‚   โ””โ”€โ”€ replay_agent.py      # Replay recordings
โ”œโ”€โ”€ core.py                  # ServiceAgent & APIWrapper
โ”œโ”€โ”€ decorators.py            # @contract decorator
โ”œโ”€โ”€ contract_types.py        # Validators (must_be_number, etc.)
โ”œโ”€โ”€ config.py                # API configurations
โ””โ”€โ”€ test_utils.py            # Test utilities

scaffolds/                   # Generated request templates
recordings/                  # Recorded API responses
tests/                       # Contract tests
services/                    # Example services

๐Ÿ“‹ Current Capabilities

โœ… OpenAPI 2.0 & 3.x parsing
โœ… Automatic scaffolding
โœ… Contract validation
โœ… PII detection & sanitization
โœ… Field filtering (only_allow, prohibits)
โœ… Recording/Replay
โœ… Live/Replay mode switching
โœ… FastAPI integration
โœ… CLI tooling


๐Ÿš€ Roadmap

Phase 1: Enhanced Validators

  • Email, URL, phone validation
  • Regex patterns
  • Range validation (min/max)
  • Enum validation
  • Array validation (minItems, unique)

Phase 2: Mock Server

  • Generate mock server from OpenAPI spec
  • Stateful mocks (CRUD operations)
  • Scenario-based responses

Phase 3: Advanced Policies

  • GDPR compliance checks
  • Rate limiting
  • Audit logging
  • Field-level encryption

Phase 4: Developer Experience

  • Web UI for contract management
  • HTML test reports
  • Interactive CLI
  • Better error messages

๐Ÿค Contributing

Contributions welcome! This project has huge potential:

  • Contract testing
  • API safety & compliance
  • Policy enforcement
  • Mock servers
  • Observability

๐Ÿ“„ License

[Your License Here]


๐ŸŽ“ Learn More


๐Ÿ’ก Use Cases

โœ… Contract Testing - Verify APIs meet expectations without full integration tests
โœ… Third-Party APIs - Validate APIs you don't control
โœ… Compliance - GDPR, HIPAA, PII protection
โœ… Testing - Deterministic tests with recording/replay
โœ… Microservices - Runtime validation between services
โœ… API Gateways - Validate before forwarding to clients


Built with โค๏ธ for API safety and testing

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

servicedock-0.1.1.tar.gz (20.4 kB view details)

Uploaded Source

Built Distribution

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

servicedock-0.1.1-py3-none-any.whl (18.3 kB view details)

Uploaded Python 3

File details

Details for the file servicedock-0.1.1.tar.gz.

File metadata

  • Download URL: servicedock-0.1.1.tar.gz
  • Upload date:
  • Size: 20.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.5

File hashes

Hashes for servicedock-0.1.1.tar.gz
Algorithm Hash digest
SHA256 eefbf652f3674552ea40088cd6db46be1a104c4afe1db3ca641beaf79aea712b
MD5 f54e51813b00218e56d8801f485a4c36
BLAKE2b-256 a0f091f63c0570316c5bb2d6a0d1f247bcb0d5bd7ac3493bca5fa114534ac593

See more details on using hashes here.

File details

Details for the file servicedock-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: servicedock-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 18.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.5

File hashes

Hashes for servicedock-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 4ea3db73bc6eb6a19e3f9a0ce467d4edf8742fde60db07dd9719746370400e4a
MD5 650033fce4f26d9cf84e319e28d40055
BLAKE2b-256 0d7ffe418c29f20991e56de2308298a086133cc232c8e1a67d5b27739b18cd37

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