Local Development Setup
This guide walks you through setting up a local development environment for the WispHub API. This is ideal for development, testing, and debugging.Prerequisites
- Python 3.12 or higher
- pip (Python package manager)
- git
- WispHub API credentials (API key and host URL)
Python 3.12 is required to match the production environment. Check your version:
Installation Steps
Create Virtual Environment
Create an isolated Python environment:This creates a
venv directory containing the Python interpreter and packages.Activate Virtual Environment
Linux/macOS:Windows:Your prompt should now be prefixed with
(venv) to indicate the virtual environment is active.Install Dependencies
Install both application and development dependencies:Application dependencies (Development dependencies (
requirements.txt):requirements-dev.txt):Running the Development Server
Using Uvicorn (Recommended for Development)
Uvicorn provides hot-reload functionality for rapid development:--reload: Automatically restart on code changes--host 0.0.0.0: Listen on all network interfaces--port 8000: Port to bind to
Using Gunicorn (Production-like)
To test the production configuration locally:Gunicorn doesn’t support
--reload. Use Uvicorn for development.Verify Installation
Health Check
Test the health endpoint:Interactive API Documentation
Open your browser to:- Interactive API explorer (Swagger UI)
- Complete endpoint documentation
- Request/response schemas
- Try-it-out functionality
Alternative Documentation
ReDoc format:Running Tests
Unit and Integration Tests
Run the full test suite with pytest:-v: Verbose output-s: Show print statements--tb=short: Shorter traceback format
Run Specific Test File
Run Specific Test Function
Test Configuration
The test suite usespytest.ini for configuration:
pytest.ini
Test Structure
Example Test
tests/api/test_clients.py
respx to mock HTTP calls to WispHub Net, ensuring tests don’t require external connectivity.
Code Quality Tools
Linting (Optional)
Consider adding linting tools:Type Checking (Optional)
Code Formatting (Optional)
IDE Configuration
VS Code
Create.vscode/settings.json:
.vscode/settings.json
PyCharm
- Configure Interpreter: File → Settings → Project → Python Interpreter
- Select venv: Choose
venv/bin/pythonas the interpreter - Enable pytest: File → Settings → Tools → Python Integrated Tools → Testing → pytest
Hot Reload Workflow
With Uvicorn’s--reload flag, development is seamless:
- Start server:
uvicorn app.main:app --reload - Make code changes: Edit any
.pyfile - Auto-restart: Server automatically detects changes and reloads
- Test immediately: Send requests to see changes
Database Seeding (if needed)
The WispHub API doesn’t maintain its own database - it proxies to WispHub Net. No local seeding is required.
- Point to a WispHub test instance
- Use
respxmocking in tests - Create a mock WispHub server for integration testing
Debugging
VS Code Debugger
Create.vscode/launch.json:
.vscode/launch.json
Print Debugging
Uvicorn shows all print statements:Logging
Use Python’s logging module:Troubleshooting
Issue: “ModuleNotFoundError”
Cause: Virtual environment not activated or dependencies not installed Solution:Issue: “Port 8000 already in use”
Cause: Another process is using port 8000 Solution: Use a different port or kill the existing process:Issue: “Field required” validation error
Cause: Missing environment variables Solution: Ensure.env file exists and contains required variables:
Issue: Tests failing with network errors
Cause: Tests are trying to connect to real WispHub Net Solution: Ensurerespx mocking is properly configured in tests. Check conftest.py for fixtures.
Development Best Practices
Use Hot Reload
Always run with
--reload during development for instant feedbackWrite Tests First
Follow TDD - write tests before implementing features
Mock External APIs
Use
respx to mock WispHub Net calls in testsCheck Types
Leverage Pydantic’s type validation for early error detection
