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.
๐ฏ 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:
- Scaffold โ
servicedock init --api dogapi(or--api myapi --url https://...) - Call & record โ
servicedock call breed.breed.images.random.get --breed husky - 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
- User workflow (start here) โ Steps 1โn: clone an API, record, use in code, run tests
- Contract features & demos โ What
@contractcan do (expects, only_allow, prohibits, PII, mode) with runnable showcase - Demo Walkthrough - Full end-to-end example with Dog API
- Project Review - Architecture, capabilities, roadmap
- Examples - Sample implementations
๐ 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:
- OpenAPI Spec:
service_agent/specs/dogapi.json - Scaffolds:
scaffolds/breed.*.get.json - Recordings:
recordings/breed.*.json - Contract Tests:
tests/test_contract_dog_api.py - 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
- Why not just use OpenAPI CodeGen? See PROJECT_REVIEW.md
- Full walkthrough: See DEMO_WALKTHROUGH.md
- Examples: Check out
examples/andservices/
๐ก 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
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 servicedock-0.1.0.tar.gz.
File metadata
- Download URL: servicedock-0.1.0.tar.gz
- Upload date:
- Size: 18.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
74aab069f5f923c7eae524c86800865de20a9689ba3f3f37d49ae139c182a276
|
|
| MD5 |
af23d6a0eb235fa45f5aeacc7494b930
|
|
| BLAKE2b-256 |
24a75c022c34a37547d4e980eb67e6f01d3644d721f77f1ef91c26e1ceaccf25
|
File details
Details for the file servicedock-0.1.0-py3-none-any.whl.
File metadata
- Download URL: servicedock-0.1.0-py3-none-any.whl
- Upload date:
- Size: 15.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d33edbff575f74d76b376448ad15ada04057c813c870e7cab5b7f78717294db5
|
|
| MD5 |
2f9a7de631a01e70daf028d8493d4ac5
|
|
| BLAKE2b-256 |
861b668556fb787b3567b553e9b4ef6324dcee51c47186f93c07fd3d077f098c
|