This guide provides comprehensive instructions for setting up, developing, and deploying the Dev API Vault application.
- Local Development Setup
- Project Structure
- Configuration
- Running the Application
- Testing
- Code Quality
- Docker Deployment
- Production Deployment
- Contributing
- Python 3.9 or higher
- pip package manager
- Git
- Optional: Docker for containerized development
git clone https://github.com/KrunalValvi/Dev_Api_Vault.git
cd Dev_Api_Vault# Create virtual environment
python -m venv venv
# Activate virtual environment
# On Windows:
venv\Scripts\activate
# On macOS/Linux:
source venv/bin/activate# Install production dependencies
pip install -r requirements.txt
# For development, also install dev dependencies
pip install pytest pytest-asyncio pytest-cov black flake8 isort mypy# Copy example environment file
cp .env.example .env
# Edit .env file with your configuration
# At minimum, set RAPIDAPI_PROXY_SECRETpython -c "import nltk; nltk.download('punkt'); nltk.download('stopwords')"Dev_Api_Vault/
├── app/ # Main application package
│ ├── __init__.py
│ ├── main.py # FastAPI application entry point
│ ├── config.py # Configuration management
│ ├── models.py # Pydantic models
│ ├── routers.py # API route handlers
│ ├── security.py # Authentication and security
│ ├── middleware.py # Rate limiting and other middleware
│ └── utils.py # Security and utility functions
├── tests/ # Test suite
│ ├── __init__.py
│ ├── conftest.py # Test configuration and fixtures
│ └── test_api.py # Comprehensive API tests
├── .env.example # Example environment variables
├── .env # Environment variables (create from example)
├── requirements.txt # Python dependencies
├── Dockerfile # Docker container definition
├── docker-compose.yml # Docker Compose configuration
├── API_REFERENCE.md # API documentation
├── DEVELOPMENT.md # This file
└── README.md # Project overview
Create a .env file with the following variables:
# Required
RAPIDAPI_PROXY_SECRET=your_secret_key_here
# Optional (with defaults)
FASTAPI_ENV=development
DEBUG=True
LOG_LEVEL=INFO
RATE_LIMIT_REQUESTS_PER_MINUTE=60
REQUEST_TIMEOUT=10
ALLOWED_ORIGINS=["*"]The application uses Pydantic Settings for configuration management:
from app.config import settings
# Access configuration
print(settings.rapidapi_proxy_secret)
print(settings.is_production)
print(settings.rate_limit_requests_per_minute)# Using uvicorn directly
uvicorn app.main:app --reload --host 0.0.0.0 --port 8000
# Or using the VS Code built-in task (if configured)
# Ctrl+Shift+P -> "Tasks: Run Task" -> "Run FastAPI Dev Server"# Using gunicorn for production
gunicorn app.main:app -w 4 -k uvicorn.workers.UvicornWorker --bind 0.0.0.0:8000- API Base: http://localhost:8000
- Interactive Docs: http://localhost:8000/docs
- ReDoc: http://localhost:8000/redoc
- Health Check: http://localhost:8000/health
# Run all tests
pytest
# Run with coverage
pytest --cov=app --cov-report=html
# Run specific test file
pytest tests/test_api.py
# Run specific test class
pytest tests/test_api.py::TestMarkdownToHtml
# Run with verbose output
pytest -v
# Run tests in parallel (install pytest-xdist first)
pytest -n autoThe test suite includes:
- Unit Tests: Individual function testing
- Integration Tests: API endpoint testing
- Security Tests: Authentication and input validation
- Error Handling Tests: Edge cases and error conditions
# Example test function
def test_new_endpoint(test_client, test_headers):
response = test_client.post(
"/api/v1/new-endpoint",
json={"data": "test"},
headers=test_headers
)
assert response.status_code == 200
assert "expected_field" in response.json()# Format code with black
black app/ tests/
# Sort imports with isort
isort app/ tests/
# Check code style with flake8
flake8 app/ tests/# Run mypy for type checking
mypy app/Install pre-commit hooks to automatically format code:
pip install pre-commit
pre-commit install
# Run hooks manually
pre-commit run --all-files- Follow PEP 8 style guide
- Use type hints for all functions
- Write docstrings for all public functions
- Keep functions focused and small
- Use meaningful variable names
- Add comments for complex logic
# Build the Docker image
docker build -t dev-api-vault .
# Build with specific tag
docker build -t dev-api-vault:v2.0.0 .# Run single container
docker run -d \
--name dev-api-vault \
-p 8000:8000 \
-e RAPIDAPI_PROXY_SECRET=your_secret \
dev-api-vault
# Run with Docker Compose
docker-compose up -d
# View logs
docker-compose logs -f api# docker-compose.yml
version: '3.8'
services:
api:
build: .
ports:
- "8000:8000"
environment:
- RAPIDAPI_PROXY_SECRET=${RAPIDAPI_PROXY_SECRET}
- FASTAPI_ENV=production
restart: unless-stopped- Python 3.9+
- 512MB RAM minimum (1GB recommended)
- 100MB disk space
- HTTPS support recommended
- Connect GitHub repository
- Set build command:
pip install -r requirements.txt - Set start command:
uvicorn app.main:app --host 0.0.0.0 --port $PORT - Add environment variables
# Create Procfile
echo "web: uvicorn app.main:app --host 0.0.0.0 --port \$PORT" > Procfile
# Deploy
git add .
git commit -m "Deploy to Heroku"
git push heroku main# .do/app.yaml
name: dev-api-vault
services:
- name: api
source_dir: /
github:
repo: KrunalValvi/Dev_Api_Vault
branch: main
run_command: uvicorn app.main:app --host 0.0.0.0 --port $PORT
environment_slug: python
instance_count: 1
instance_size_slug: basic-xxsRAPIDAPI_PROXY_SECRET=secure_random_secret
FASTAPI_ENV=production
DEBUG=False
LOG_LEVEL=WARNING
RATE_LIMIT_REQUESTS_PER_MINUTE=100
ALLOWED_ORIGINS=["https://yourdomain.com"]- Set secure
RAPIDAPI_PROXY_SECRET - Set
FASTAPI_ENV=production - Set
DEBUG=False - Configure proper
ALLOWED_ORIGINS - Set up HTTPS/SSL
- Configure monitoring and logging
- Set up backup strategy
- Test all endpoints in production environment
- Rate Limiting: Configured per environment
- Request Timeouts: Configurable timeout values
- Content Limits: File size and text length limits
- Connection Pooling: Reuse HTTP connections
- Caching: Consider Redis for response caching
# Use multiple workers for production
gunicorn app.main:app \
-w 4 \
-k uvicorn.workers.UvicornWorker \
--bind 0.0.0.0:8000 \
--max-requests 1000 \
--max-requests-jitter 100import logging
# Configure logging in production
logging.basicConfig(
level=logging.INFO,
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s",
handlers=[
logging.FileHandler("app.log"),
logging.StreamHandler()
]
)- Monitor
/healthendpoint - Set up alerts for 4xx/5xx errors
- Monitor response times
- Track rate limit violations
- Fork the repository
- Create feature branch:
git checkout -b feature/new-feature - Make changes and add tests
- Run test suite:
pytest - Check code quality:
black . && isort . && flake8 . - Commit changes:
git commit -m "Add new feature" - Push branch:
git push origin feature/new-feature - Create Pull Request
- Include tests for new features
- Update documentation as needed
- Follow existing code style
- Add changelog entry
- Ensure all CI checks pass
- Automated checks (tests, linting, security)
- Manual code review by maintainers
- Address feedback and update PR
- Final approval and merge
Import Errors
# Ensure all dependencies are installed
pip install -r requirements.txt
# Check Python path
python -c "import sys; print(sys.path)"NLTK Data Missing
python -c "import nltk; nltk.download('punkt'); nltk.download('stopwords')"Port Already in Use
# Find process using port 8000
lsof -i :8000
# Kill process
kill -9 <PID>Environment Variables Not Loading
# Check .env file exists and is readable
ls -la .env
# Verify environment loading
python -c "from app.config import settings; print(settings.dict())"Enable debug mode for development:
export DEBUG=True
export FASTAPI_ENV=developmentThis enables:
- Detailed error messages
- Auto-reload on code changes
- Interactive API documentation
- Verbose logging
- Never commit secrets to version control
- Use
.envfiles for local configuration - Regularly update dependencies
- Run security audits:
pip audit
- Use strong, random secrets
- Enable HTTPS only
- Configure CORS properly
- Monitor for suspicious activity
- Regular security updates
For issues and questions:
- GitHub Issues: Create Issue
- Documentation: API Reference
- Email: Create an issue for support requests