Added a /healthz health check endpoint to the Python SDK as requested in Issue #62.
-
scrapegraph_py/client.py- Added
healthz()method to the synchronous Client class - Added mock response support for
/healthzendpoint - Full documentation and logging support
- Added
-
scrapegraph_py/async_client.py- Added
healthz()method to the asynchronous AsyncClient class - Added mock response support for
/healthzendpoint - Full async/await support with proper error handling
- Added
-
examples/utilities/healthz_example.py- Basic synchronous health check example
- Monitoring integration example
- Exit code handling for scripts
-
examples/utilities/healthz_async_example.py- Async health check example
- Concurrent health checks demonstration
- FastAPI integration pattern
- Advanced monitoring patterns
-
tests/test_client.py- Added
test_healthz()- test basic health check - Added
test_healthz_unhealthy()- test unhealthy status
- Added
-
tests/test_async_client.py- Added
test_healthz()- async test basic health check - Added
test_healthz_unhealthy()- async test unhealthy status
- Added
-
tests/test_healthz_mock.py(New file)- Comprehensive mock mode tests
- Tests for both sync and async clients
- Custom mock response tests
- Environment variable tests
-
HEALTHCHECK.md(New file at root)- Complete documentation for the SDK
- API reference
- Usage examples
- Integration patterns (FastAPI)
- Docker and Kubernetes examples
- Best practices
-
IMPLEMENTATION_SUMMARY.md(This file)- Summary of all changes
- File structure
- Testing results
✅ GET /healthz endpoint implementation
✅ Synchronous client support (Python)
✅ Asynchronous client support (Python)
✅ Proper error handling
✅ Logging support
✅ Built-in mock responses ✅ Custom mock response support ✅ Mock handler support ✅ Environment variable control
✅ Unit tests for Python sync client ✅ Unit tests for Python async client ✅ Mock mode tests ✅ All tests passing
✅ Inline code documentation ✅ Python docstrings ✅ Comprehensive user guide ✅ Integration examples ✅ Best practices guide
✅ Basic usage examples ✅ Advanced monitoring patterns ✅ Framework integrations (FastAPI) ✅ Container health checks (Docker) ✅ Kubernetes probes ✅ Retry logic patterns
Running health check mock tests...
============================================================
✓ Sync health check mock test passed
✓ Sync custom mock response test passed
✓ from_env mock test passed
============================================================
✅ All synchronous tests passed!
pytest results:
======================== 5 passed, 39 warnings in 0.25s ========================
scrapegraph-sdk/
├── HEALTHCHECK.md # Complete documentation
├── IMPLEMENTATION_SUMMARY.md # This file
│
└── scrapegraph-py/
├── scrapegraph_py/
│ ├── client.py # ✨ Added healthz() method
│ └── async_client.py # ✨ Added healthz() method
├── examples/utilities/
│ ├── healthz_example.py # 🆕 New example
│ └── healthz_async_example.py # 🆕 New example
└── tests/
├── test_client.py # ✨ Added tests
├── test_async_client.py # ✨ Added tests
└── test_healthz_mock.py # 🆕 New test file
Legend:
- 🆕 New file
- ✨ Modified file
# Synchronous
client.healthz() -> dict
# Asynchronous
await client.healthz() -> dict{
"status": "healthy",
"message": "Service is operational"
}from scrapegraph_py import Client
client = Client.from_env()
health = client.healthz()
print(health)
client.close()from scrapegraph_py import AsyncClient
async with AsyncClient.from_env() as client:
health = await client.healthz()
print(health)livenessProbe:
exec:
command:
- python
- -c
- |
from scrapegraph_py import Client
import sys
c = Client.from_env()
h = c.healthz()
c.close()
sys.exit(0 if h.get('status') == 'healthy' else 1)
initialDelaySeconds: 10
periodSeconds: 30HEALTHCHECK --interval=30s --timeout=3s --retries=3 \
CMD python -c "from scrapegraph_py import Client; import sys; c = Client.from_env(); h = c.healthz(); c.close(); sys.exit(0 if h.get('status') == 'healthy' else 1)"- ✅ Implementation complete
- ✅ Tests written and passing
- ✅ Documentation complete
- ✅ Examples created
- 🔲 Merge to main branch
- 🔲 Release new version
- 🔲 Update public documentation
- All code follows existing SDK patterns and conventions
- Mock mode support ensures tests can run without API access
- Comprehensive error handling included
- Logging integrated throughout
- Documentation includes real-world integration examples
- All tests passing successfully
- Python: 3.8+
- Fully backward compatible with existing SDK functionality