A modern, web-based IP Address Management (IPAM) system built with Flask, SQLite, Bootstrap, and DataTables.
- π Network Management: Manage IP networks with CIDR notation
- π₯οΈ Host Management: Track IP addresses, hostnames, and MAC addresses
- π REST API: Complete RESTful API with Swagger UI documentation
- π Dashboard: Clear overview of network utilization
- π Advanced Search: DataTables integration for efficient data filtering
- π± Responsive Design: Bootstrap 5 for modern, mobile-friendly UI
- π³ Container-ready: Docker support for easy deployment
- β Fully Tested: Comprehensive unit tests with pytest
-
Install pyenv (if not already installed):
macOS with Homebrew:
brew install pyenv
Linux/macOS with curl:
curl https://pyenv.run | bash
-
Shell Configuration (for bash/zsh):
echo 'export PATH="$HOME/.pyenv/bin:$PATH"' >> ~/.bashrc echo 'eval "$(pyenv init -)"' >> ~/.bashrc echo 'eval "$(pyenv virtualenv-init -)"' >> ~/.bashrc source ~/.bashrc
-
Clone repository:
git clone <repository-url> cd ipam
-
Install and activate Python version:
pyenv install 3.13 pyenv local 3.13
-
Create virtual environment:
python -m venv venv source venv/bin/activate # Linux/macOS # or venv\\Scripts\\activate # Windows
-
Install dependencies:
pip install -r requirements.txt
-
Configure environment variables:
cp .env.example .env # Edit .env as needed
-
Initialize database:
python3 -c "from ipam import create_app; from ipam.extensions import db; app = create_app(); app.app_context().push(); db.create_all()"
-
Start application:
python app.py
The application will be available at:
- Web Interface: http://localhost:5000
- REST API: http://localhost:5000/api/v1
- API Documentation (Swagger UI): http://localhost:5000/api/v1/docs
# Run all tests
pytest
# Tests with coverage report
pytest --cov=app --cov-report=html
# Run specific tests
pytest tests/test_models.py
# Tests in watch mode (with pytest-watch)
pip install pytest-watch
ptw
The production Docker image is built on Chainguard distroless Python images for maximum security:
Security Features:
- β 0 CRITICAL/HIGH vulnerabilities (Trivy scanned)
- β Multi-stage build with minimal attack surface
- β Distroless runtime (no shell, package manager)
- β Runs as nonroot user (UID 65532)
- β Includes SBOM (Software Bill of Materials)
- β Python 3.13
Image Details:
- Size: ~50-100MB (vs 200-300MB for standard Python images)
- Base: cgr.dev/chainguard/python:latest (distroless)
- Registry: ghcr.io/tuxpeople/python-ipam
# Pull and run production image
docker pull ghcr.io/tuxpeople/python-ipam:latest
docker run -d -p 5000:5000 \
-v $(pwd)/ipam.db:/app/ipam.db \
ghcr.io/tuxpeople/python-ipam:latest
# Or use Docker Compose
docker-compose up -d
# With custom .env file
cp .env.example .env
# Edit .env for production settings
docker-compose up -d
# Development environment with hot-reload
docker-compose --profile dev up
# Or build locally
docker build -t python-ipam:dev .
docker run -p 5000:5000 python-ipam:dev
The complete REST API is available at /api/v1
. Interactive API documentation (Swagger UI) can be found at http://localhost:5000/api/v1/docs
Networks:
GET /api/v1/networks
- List all networks with filtering and paginationGET /api/v1/networks/{id}
- Get specific networkPOST /api/v1/networks
- Create new networkPUT /api/v1/networks/{id}
- Update networkDELETE /api/v1/networks/{id}
- Delete network
Hosts:
GET /api/v1/hosts
- List all hosts with filtering and paginationGET /api/v1/hosts/{id}
- Get specific hostPOST /api/v1/hosts
- Create new hostPUT /api/v1/hosts/{id}
- Update hostDELETE /api/v1/hosts/{id}
- Delete host
IP Management:
GET /api/v1/ip/networks/{id}/next-ip
- Get next available IPGET /api/v1/ip/networks/{id}/available-ips
- List all available IPsGET /api/v1/ip/{ip_address}
- Query IP address status
See API.md for complete documentation
ipam/
βββ app.py # Flask application entry point
βββ requirements.txt # Python dependencies
βββ pytest.ini # Pytest configuration
βββ Dockerfile # Docker container definition
βββ docker-compose.yml # Docker Compose configuration
βββ .env.example # Example environment variables
βββ ipam/ # Main application package
β βββ __init__.py # Application Factory
β βββ extensions.py # Flask extensions (SQLAlchemy)
β βββ models.py # Database models
β βββ forms.py # WTForms
β βββ config.py # Configuration
β βββ api/ # REST API Blueprint
β β βββ __init__.py # API Blueprint and Swagger
β β βββ models.py # API serialization models
β β βββ networks.py # Network endpoints
β β βββ hosts.py # Host endpoints
β β βββ ip_management.py # IP management endpoints
β βββ web/ # Web Interface Blueprint
β βββ __init__.py # Web Blueprint
β βββ routes.py # Web routes
βββ templates/ # HTML Templates (Jinja2)
β βββ base.html # Base template
β βββ index.html # Dashboard
β βββ networks.html # Network overview
β βββ hosts.html # Host overview
β βββ add_network.html # Add network
β βββ add_host.html # Add host
β βββ edit_network.html # Edit network
β βββ edit_host.html # Edit host
βββ exporters/ # Export plugins
β βββ base_exporter.py # Base exporter class
β βββ csv_exporter.py # CSV export
β βββ json_exporter.py # JSON export
β βββ dnsmasq_exporter.py # DNSmasq config export
βββ importers/ # Import plugins
β βββ base_importer.py # Base importer class
β βββ csv_importer.py # CSV import
β βββ json_importer.py # JSON import
βββ tests/ # Test suite
βββ conftest.py # Pytest fixtures
βββ test_models.py # Model tests
βββ test_routes.py # Route tests
βββ test_forms.py # Form tests
βββ test_database.py # Database tests
βββ test_export_import.py # Export/Import tests
βββ test_crud_operations.py # CRUD tests
id
- Primary Keynetwork
- Network address (e.g., "192.168.1.0")cidr
- CIDR suffix (e.g., 24)broadcast_address
- Broadcast addressname
- Network name (optional)domain
- DNS domain (optional)vlan_id
- VLAN ID (optional)description
- Description (optional)location
- Location (optional)
id
- Primary Keyip_address
- IP address (unique)hostname
- Hostname (optional)cname
- DNS alias/CNAME (optional)mac_address
- MAC address (optional)description
- Description (optional)status
- Status (active/inactive/reserved)network_id
- Foreign Key to Networks
- Code Style: Follow PEP 8
- Tests: Write tests for new features
- Commits: Use meaningful commit messages
- Branches: Use feature branches for new development
- Backend: Flask 3.1, SQLAlchemy 2.0, Flask-RESTX
- Frontend: Bootstrap 5, jQuery, DataTables
- Database: SQLite (production-ready for small to medium deployments)
- Testing: pytest, pytest-flask (96 tests)
- Containerization: Docker (Chainguard distroless), Docker Compose
- Security: Trivy scanning, SBOM generation, multi-stage builds
- CI/CD: GitHub Actions (tests, security scans, docs deployment)
[Specify license here]
Contributions are welcome! Please create issues for bug reports or feature requests.