Skip to main content

🛡️ 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. Scaffoldservicedock init --api dogapi (or --api myapi --url https://...)
  2. Call & recordservicedock call breed.breed.images.random.get --breed husky
  3. TestPYTHONPATH=. 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

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.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 files

0.1.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page