Search, retrieve, and cite New Zealand legislation in seconds.
A fast, friendly command-line tool for researchers, legal professionals, and anyone working with NZ legislation. Get your research done fasterβwith less copying and pasting.
Package links: npm package Β· GitHub repository
nz-legislation-tool@edithatogo/nz-legislation-toolThe GitHub repository "Packages" area is populated by GitHub Packages publishes, not by the public npmjs.com listing. This repository includes a workflow to publish a scoped GitHub Packages mirror so the repo can show a package entry there as well.
Use the CLI if you want direct terminal access for search, retrieval, export, and citation.
npm install -g nz-legislation-tool
nzlegislation search --query "health act"
Use the MCP server if you want to connect the tool to an AI assistant or tool-calling environment.
npm install -g nz-legislation-tool
nzlegislation-mcp
Example MCP command configuration:
{
"command": "nzlegislation-mcp",
"env": {
"NZ_LEGISLATION_API_KEY": "your-api-key"
}
}
Option A: Try without installing (recommended for first time)
npx nz-legislation-tool search --query "health"
Option B: Install globally (recommended for regular use)
npm install -g nz-legislation-tool
nzlegislation config --key YOUR_API_KEY_HERE
nzlegislation search --query "health act"
You should see:
ββββββββββββββββββββββ¬βββββββββββββββββββββββββββββββββββββββββββ¬βββββββββ¬βββββββββββ¬βββββββββββββ
β ID β Title β Type β Status β Date β
ββββββββββββββββββββββΌβββββββββββββββββββββββββββββββββββββββββββΌβββββββββΌβββββββββββΌβββββββββββββ€
β act/2020/67 β Health Act 2020 β act β in-force β 2020-11-15 β
β act/1956/65 β Health Act 1956 β act β repealed β 1956-10-01 β
ββββββββββββββββββββββ΄βββββββββββββββββββββββββββββββββββββββββββ΄βββββββββ΄βββββββββββ΄βββββββββββββ
Total: 42 results (showing 25)
π That's it! You're ready to go.
search - Find LegislationSearch the entire NZ legislation database.
# Basic search
nzlegislation search --query "health"
# Filter by type (act, bill, regulation, instrument)
nzlegislation search --query "health" --type act
# Filter by status (in-force, repealed, etc.)
nzlegislation search --query "mental health" --status in-force
# Search by date range
nzlegislation search --query "health" --from 2020-01-01 --to 2024-12-31
# Export results to CSV
nzlegislation search --query "health" --format csv --output results.csv
All options:
| Option | Short | Description | Default |
|---|---|---|---|
--query |
-q |
Search query (required) | - |
--type |
-t |
Filter: act, bill, regulation, instrument | - |
--status |
-s |
Filter: in-force, repealed, etc. | - |
--from |
- | From date (YYYY-MM-DD) | - |
--to |
- | To date (YYYY-MM-DD) | - |
--limit |
-l |
Max results (1-100) | 25 |
--offset |
-o |
For pagination | 0 |
--format |
-f |
Output: table, json, csv | table |
π Pro tip: Use quotes for multi-word searches: "Mental Health Act"
get - View Specific LegislationGet full details for a specific Act or regulation.
# Get details by ID
nzlegislation get "act/2020/67"
# Include version history
nzlegislation get "act/2020/67" --versions
# Output as JSON
nzlegislation get "act/2020/67" --format json
Where do I find the ID?
Run a search first, then copy the ID from the results:
nzlegislation search --query "health act"
# Copy "act/2020/67" from the results
export - Download Results to FilePerfect for analysis in Excel, R, or Python.
# Export to CSV (most common)
nzlegislation export --query "health" --output health.csv
# Export to JSON (for developers)
nzlegislation export --query "health" --format json --output health.json
# Filtered export (e.g., only active Acts)
nzlegislation export --query "mental health" --type act --status in-force --output mental_health_acts.csv
# Include metadata for reproducibility
nzlegislation export --query "health" --output health.csv --include-metadata
All options:
| Option | Short | Description | Default |
|---|---|---|---|
--query |
-q |
Search query (required) | - |
--output |
-o |
Output file path (required) | - |
--format |
-f |
Output: csv, json | csv |
--type |
-t |
Filter by type | - |
--status |
-s |
Filter by status | - |
--from |
- | From date | - |
--to |
- | To date | - |
--limit |
-l |
Max results | 100 |
--include-metadata |
- | Add export metadata | false |
cite - Generate CitationsCreate citations for papers, theses, or reports.
# NZMJ style (default - for New Zealand Medical Journal)
nzlegislation cite "act/2020/67"
# BibTeX (for LaTeX papers)
nzlegislation cite "act/2020/67" --style bibtex
# RIS (for EndNote, Mendeley, Zotero)
nzlegislation cite "act/2020/67" --style ris
# APA style
nzlegislation cite "act/2020/67" --style apa
Build a bibliography:
# Append multiple citations to a .bib file
nzlegislation cite "act/1981/118" --style bibtex >> references.bib
nzlegislation cite "act/2020/67" --style bibtex >> references.bib
config - Manage SettingsView and update your configuration.
# Show current settings
nzlegislation config --show
# Update API key
nzlegislation config --key YOUR_NEW_KEY
# Clear all settings (start fresh)
nzlegislation config --clear
Rachel is writing a paper on health policy reform.
# 1. Find all active health Acts
nzlegislation search --query "health" --type act --status in-force
# 2. Export for analysis in Excel
nzlegislation export --query "health" --type act --output health_acts.csv
# 3. Get details on a specific Act
nzlegislation get "act/2020/67"
# 4. Generate citation for her paper
nzlegislation cite "act/2020/67" --style nzmj
Dan is building a research dashboard.
# Get data in JSON format for his app
nzlegislation search --query "health" --format json --limit 100
# Parse in Node.js:
const results = JSON.parse(output);
console.log(`Found ${results.total} results`);
Sam needs legislation for a coursework essay.
# Search for the Mental Health Act
nzlegislation search --query "Mental Health Act" --type act
# Get the full details
nzlegislation get "act/1992/100"
# Generate APA citation for the bibliography
nzlegislation cite "act/1992/100" --style apa
Alex is deploying for a research team.
# Install on shared server
npm install -g nz-legislation-tool
# Configure API key for the team
nzlegislation config --key $TEAM_API_KEY
# Test it works
nzlegislation search --query "test" --limit 1
# Set up monitoring (check rate limits)
nzlegislation config --show
Beautiful, readable tables right in your terminal:
ββββββββββββββββββββββ¬βββββββββββββββββββββββββββββββββββββββββββ¬βββββββββ¬βββββββββββ¬βββββββββββββ
β ID β Title β Type β Status β Date β
ββββββββββββββββββββββΌβββββββββββββββββββββββββββββββββββββββββββΌβββββββββΌβββββββββββΌβββββββββββββ€
β act/2020/67 β Health Act 2020 β act β in-force β 2020-11-15 β
β act/1956/65 β Health Act 1956 β act β repealed β 1956-10-01 β
ββββββββββββββββββββββ΄βββββββββββββββββββββββββββββββββββββββββββ΄βββββββββ΄βββββββββββ΄βββββββββββββ
For developers and automation:
{
"total": 42,
"offset": 0,
"limit": 25,
"results": [
{
"id": "act/2020/67",
"title": "Health Act 2020",
"type": "act",
"status": "in-force",
"date": "2020-11-15"
}
]
}
Ready for Excel, R, Python, or SPSS:
id,title,shortTitle,type,status,date,url,versionCount
act/2020/67,Health Act 2020,Health Act 2020,act,in-force,2020-11-15,https://api.legislation.govt.nz/v0/works/act/2020/67,5
The NZ Legislation API has fair use limits:
| Limit | Value | Reset |
|---|---|---|
| Daily | 10,000 requests | Midnight local time |
| Burst | 2,000 requests per 5 minutes | Rolling window |
Don't worryβthe CLI automatically handles rate limiting. If you hit a limit, you'll see a friendly message telling you when to try again.
Quick fix:
nzlegislation config --key YOUR_API_KEY
Still not working? Check if it's set correctly:
nzlegislation config --show
Common causes:
Fix it:
nzlegislation config --key YOUR_KEYnzlegislation search --query "test"What happened: You've made too many requests too quickly.
Fix it:
Prevent it:
--limit to reduce batch sizesCommon causes:
act/2020/67)Fix it:
nzlegislation search --query "health"
What happened: Can't connect to the API.
Fix it:
Still stuck? Check the API status or contact support.
npm install -g nz-legislation-tool
Pros: Use anywhere, no need to type npx
Cons: Takes up disk space (~50MB)
npx nz-legislation-tool search --query "health"
Pros: No installation, try before committing
Cons: Slower (downloads each time), need to type npx
git clone https://github.com/edithatogo/nz-legislation-tool
cd nz-legislation-tool
npm install
npm run build
npm link # Install globally
Pros: Latest features, can contribute changes
Cons: Requires build step, for advanced users
We'd love your help! This project is open source and welcomes contributions from everyone.
Ways to contribute:
See CONTRIBUTING.md for how to get started.
# Clone the repo
git clone https://github.com/edithatogo/nz-legislation-tool
cd nz-legislation-tool
# Install dependencies
npm install
# Run in development mode
npm run dev -- search --query "health"
# Run tests
npm test
Need more help? Check out these guides:
This repository runs itself with minimal manual intervention:
| Automation | Frequency | What It Does |
|---|---|---|
| π Security Audit | Weekly | Scans for vulnerabilities |
| β¨ Code Quality | Every commit | Linting, type checking |
| π¦ Dependency Updates | Weekly | Auto-updates safe packages |
| π§ͺ Tests | Every commit | 43+ automated tests |
| β‘ Benchmarks | Weekly | Performance tracking |
| ποΈ Stale Cleanup | Daily | Closes inactive issues |
Manual maintenance: ~0 hours/month β
See MAINTENANCE_GUIDE.md for details.
Need help? We're here for you.
Response time: We aim to respond within 2 business days.
Apache License 2.0 - See LICENSE for details.
TL;DR: Free to use, modify, and distribute. Just give credit and don't hold us liable.
Built with β€οΈ for New Zealand researchers, by researchers.
npm Β· GitHub Β· API Docs Β· Documentation