Development Setup
Relevant source files
The following files were used as context for generating this wiki page:
This page provides a comprehensive guide for developers to set up, configure, and contribute to the FastLimit project. FastLimit is a high-performance, Redis-backed rate limiting library designed for Python applications, particularly FastAPI. The development environment focuses on ensuring atomic operations via Redis Lua scripts and maintaining high performance with asynchronous Python.
The setup involves configuring Python 3.9+, a Redis server for state management, and various development tools for linting, type checking, and testing.
Prerequisites
Before beginning the setup, ensure the following software is installed on your local machine:
| Requirement | Version | Purpose |
|---|---|---|
| Python | 3.9+ | Primary programming language |
| Redis | 7.0+ | Backend storage for rate limit state and Lua script execution |
| Git | Latest | Version control |
| Poetry | Latest | Dependency management and packaging |
| Docker | Optional | Recommended for running containerized Redis |
Sources: CONTRIBUTING.md:43-50, README.md:211-215, pyproject.toml:26
Environment Configuration
The project uses poetry for managing dependencies and virtual environments. The setup process involves forking the repository, cloning it locally, and installing the required packages.
1. Repository Setup
# Clone the repository
git clone https://github.com/Arjun-Aravind/fastlimit.git
cd fastlimit
# Install all dependencies including development, testing, and metrics extras
pip install -e ".[dev,test,metrics]"
Sources: CONTRIBUTING.md:85-115, README.md:217-224
2. Redis Backend Setup
FastLimit requires a Redis instance for its backend operations. This can be run locally or via Docker.
# Using Docker (Recommended)
docker run -d -p 6379:6379 redis:7-alpine
# Or using docker-compose
docker-compose -f docker-compose.dev.yml up -d
Sources: CONTRIBUTING.md:120-135, README.md:267-270
The following diagram illustrates the high-level architecture of the development environment:
The diagram shows the interaction between the local Python environment and the Redis backend where Lua scripts are executed.
Sources: README.md:255-265, CONTRIBUTING.md:143-180
Development Workflow
FastLimit follows a standard open-source contribution workflow including linting, type checking, and automated testing.
Tooling and Code Style
The project enforces strict code quality through several tools configured in pyproject.toml:
- Black: Used for code formatting with a line length of 100 characters.
- Ruff: Used for linting and enforcing PEP 8, including pyupgrade and isort.
- Mypy: Used for strict type checking (required for all public functions).
- Commitizen: Used for managing conventional commits and semantic versioning.
Sources: pyproject.toml:57-105, CONTRIBUTING.md:320-345
Testing Infrastructure
The test suite is built on pytest and pytest-asyncio. It includes fixtures for managing Redis connections and ensuring database isolation between tests.
This sequence shows the lifecycle of a test case using the clean_limiter fixture to ensure environment isolation.
Sources: tests/conftest.py:34-95, CONTRIBUTING.md:235-245
Key Development Commands
| Command | Action |
|---|---|
pytest | Run the full test suite |
pytest --cov=fastlimit | Run tests with coverage reporting (Target: 90%+) |
black fastlimit/ tests/ | Format the codebase |
ruff check fastlimit/ --fix | Lint and auto-fix issues |
mypy fastlimit/ --strict | Run static type analysis |
Sources: CONTRIBUTING.md:195-215, CONTRIBUTING.md:465-485, pyproject.toml:115-120
Project Structure
Developers should familiarize themselves with the package organization:
fastlimit/: Core logic, including algorithms (Fixed Window, Token Bucket, Sliding Window) and storage backends.fastlimit/scripts/: Lua scripts for atomic Redis operations.tests/: Comprehensive test suite covering concurrency, multi-tenancy, and security.examples/: Integration samples for FastAPI and multi-tenant SaaS setups.
Sources: CONTRIBUTING.md:143-180, README.md:230-245
Conclusion
The FastLimit development setup is designed for high reliability and performance, utilizing Redis Lua scripts for atomicity and strict Python typing for maintainability. By following the standardized environment configuration and testing workflow, contributors can ensure their changes meet the project's production-ready standards.