Skip to content

This repository, nbpull, is a read-only Command Line Interface (CLI) tool designed to pull and query IP Address Management (IPAM) data from NetBox. Built with Python 3.13, it focuses on security and safety by strictly enforcing a read-only invariant.

License

Notifications You must be signed in to change notification settings

Champion2005/nbpull

πŸ” nbpull

CI Python 3.13+ License: GPL v3 Typed

Read-only CLI tool to pull IPAM data from NetBox.

πŸ”’ Safety guarantee: nbpull only reads data from NetBox. No POST / PUT / PATCH / DELETE requests are ever made. The HTTP client is hardcoded to GET-only β€” this invariant is enforced by code structure and verified by tests.


✨ Features

  • πŸ“‘ Prefixes β€” list and filter IPAM prefixes
  • πŸ–₯️ IP Addresses β€” query IP address allocations
  • 🏷️ VLANs β€” browse VLAN assignments
  • πŸ”€ VRFs β€” inspect VRF instances
  • πŸ“¦ Batch queries β€” check many prefixes at once from a TOML file
  • 🎨 Rich table output (default) or JSON (--format json)
  • πŸ”Ž Filter by status, VRF, tenant, site, tag, or free-text search
  • ⚑ Async HTTP with automatic pagination
  • πŸ”’ Strict typing (mypy strict mode + Pydantic v2)

πŸ“¦ Installation

With uv (recommended)

uv tool install nbpull

With pipx

pipx install nbpull

With pip

pip install nbpull

From source

git clone https://github.com/Champion2005/nbpull.git
cd nbpull
make install   # uses uv sync

πŸš€ Quick Start

# 1. Run the interactive setup wizard
nbpull setup

# Or configure manually:
export NETBOX_URL=https://netbox.example.com
export NETBOX_TOKEN=your_read_only_token
# Or: cp .env.example .env && edit .env

# 2. Pull data
nbpull prefixes
nbpull prefixes --status active --vrf Production
nbpull ip-addresses --prefix 10.0.0.0/24
nbpull vlans --site DC1
nbpull vrfs --tenant Ops
nbpull batch-prefixes --file my_prefixes.toml --status-only

πŸ“‹ Commands

Command Description
nbpull setup Interactive setup wizard
nbpull prefixes List IPAM prefixes
nbpull ip-addresses List IP addresses
nbpull vlans List VLANs
nbpull vrfs List VRFs
nbpull batch-prefixes Query multiple prefixes from a TOML file

Common Flags

Flag Description
--status Filter by status (active, reserved, deprecated, container)
--vrf Filter by VRF name
--tenant Filter by tenant name
--site Filter by site name
--tag Filter by tag slug
--search / -s Free-text search
--limit / -l Max results (default: 50)
--format / -f Output format: table (default) or json
--verbose / -v Enable debug logging

See the full command reference for all options.

βš™οΈ Configuration

Set these in .env or as environment variables:

Variable Required Default Description
NETBOX_URL βœ… β€” NetBox instance URL
NETBOX_TOKEN βœ… β€” API token (read-only recommended)
NETBOX_PAGE_SIZE ❌ 100 Results per API page
NETBOX_TIMEOUT ❌ 30 Request timeout (seconds)
NETBOX_VERIFY_SSL ❌ true Verify SSL certificates

See docs/configuration.md for details on token setup and SSL options.

πŸ“¦ Batch Queries

Create a TOML file to query multiple prefixes in one run:

prefixes = [
    "10.0.0.0/8",
    "172.16.0.0/12",
    "192.168.0.0/16",
]

[filters]
# status = "active"
# vrf = "Production"
nbpull batch-prefixes --file prefixes.toml --status-only

πŸ“ Architecture

src/netbox_data_puller/
β”œβ”€β”€ cli.py          # Typer commands + filtering
β”œβ”€β”€ client.py       # Async GET-only NetBox API client
β”œβ”€β”€ config.py       # Pydantic Settings (.env)
β”œβ”€β”€ formatters.py   # Rich table renderers
└── models/         # Pydantic models per resource
    β”œβ”€β”€ prefix.py
    β”œβ”€β”€ ip_address.py
    β”œβ”€β”€ vlan.py
    └── vrf.py

See docs/architecture.md for a full breakdown.

πŸ› οΈ Development

Prerequisites

  • Python 3.13+
  • uv β€” fast Python package manager

Setup

git clone https://github.com/Champion2005/nbpull.git
cd nbpull
make install    # Install dependencies

Commands

make all        # format β†’ lint β†’ typecheck β†’ test
make test       # unit tests (no network)
make lint       # ruff linter
make format     # auto-format with ruff
make typecheck  # mypy strict mode
make test-integration  # hits real NetBox API

Running Tests

Unit tests use mocked HTTP responses and require no network access:

make test

Integration tests require NETBOX_URL and NETBOX_TOKEN:

make test-integration

🀝 Contributing

Contributions are welcome! Please read CONTRIBUTING.md before opening a PR.

πŸ“ Changelog

See CHANGELOG.md for a history of changes.

πŸ“„ License

This project is licensed under the GNU General Public License v3.0 β€” see the LICENSE file for details.

πŸ™ Acknowledgements

  • NetBox β€” the leading open-source IPAM/DCIM platform
  • Typer β€” CLI framework
  • Rich β€” beautiful terminal formatting
  • httpx β€” async HTTP client
  • Pydantic β€” data validation

About

This repository, nbpull, is a read-only Command Line Interface (CLI) tool designed to pull and query IP Address Management (IPAM) data from NetBox. Built with Python 3.13, it focuses on security and safety by strictly enforcing a read-only invariant.

Resources

License

Contributing

Security policy

Stars

Watchers

Forks

Packages

 
 
 

Contributors