Skip to main content

hn-query

HN CLI utility.

Tech Stack

  • Python 3.12+ with src/ layout
  • uv — package manager
  • Typer — CLI framework
  • pytest — testing
  • Ruff — linting & formatting
  • pre-commit — git hooks

Getting Started

# Install dependencies
uv sync

# Run the CLI
uv run hn-query --help
uv run hn-query top
uv run hn-query top --json
uv run hn-query top --csv
uv run hn-query top --format human --output top.txt

# Run tests
uv run pytest

# Lint & format
uv run ruff check .
uv run ruff format .

# Set up git hooks
uv run pre-commit install

Working with AI Agents

This project includes an AGENTS.md file with instructions for AI coding agents.

Project Structure

See ARCHITECTURE.md for details on how the project is organized and how to grow it as your application evolves.

Commands

  • hn-query top: fetch top Hacker News stories (implemented)
  • hn-query new: fetch new Hacker News stories (implemented)
  • hn-query best: fetch best Hacker News stories (implemented)
  • hn-query item <id>: fetch one Hacker News item by ID (implemented)

top options

  • --limit, -n: number of stories, default 10, max 100
  • --format: human, json, or csv
  • --json: shortcut for --format json
  • --csv: shortcut for --format csv
  • --output, -o: write output to file
  • --timeout: HTTP timeout seconds

Python API (Scripts and Notebooks)

hn-query exposes a stable import API in hn_query.api and top-level re-exports in hn_query.

Script example

from hn_query import get_top, stories_to_json

stories = get_top(limit=5, timeout=10.0)
print(stories_to_json(stories))

Notebook example

from hn_query.api import get_item, item_to_json

item = get_item(8863)
item_to_json(item)

Stable exports

Top-level supported imports:

  • HNStory
  • HNApiError
  • get_top, get_new, get_best, get_item
  • stories_to_json, stories_to_csv
  • item_to_json, item_to_csv

Metadata

Release files for hn-query 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for hn-query 0.2.0
File Size Uploaded
hn_query-0.2.0.tar.gz 16.3 MB Details

Built distribution (wheel)

Table of built distributions (wheels) for hn-query 0.2.0
File Interpreter ABI Platform
hn_query-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 16.3 MB

Release files / hn_query-0.2.0.tar.gz

Download URL hn_query-0.2.0.tar.gz
Size 16.3 MB
Tags Source
SHA-256 checksum
How to use checksums
9d8c5757edf7d7f9cdfd9f0cda8ce828f920981f2cc5c537c4e8c727ab6f7295
BLAKE2b-256 checksum
How to use checksums
4c0e7f1eabe87ffa2eeaeed5949e0c15a9177dfb79bec92649d616d0655a12ac
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.10.5 {"installer":{"name":"uv","version":"0.10.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / hn_query-0.2.0-py3-none-any.whl

Download URL hn_query-0.2.0-py3-none-any.whl
Size 8.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
010d117c787d8740f1d6493a3f372eefd19f16a2c2578c91a7deb08d3570944f
BLAKE2b-256 checksum
How to use checksums
162dd246a86dd7e7255949e891554ffcacc692b3e870a80f5e1b46fdbf0a1750
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.10.5 {"installer":{"name":"uv","version":"0.10.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page