Skip to main content

Parse Keep a Changelog formatted CHANGELOG.md files into Python objects

Project description

patchnotes

Parse Keep a Changelog formatted CHANGELOG.md files into structured Python objects.

Zero dependencies. Pure Python. Typed.

import patchnotes

cl = patchnotes.parse_file("CHANGELOG.md")

cl.latest()        # Release(v2.1.0, 2024-11-15, 6 entries)
cl.unreleased()    # Release(vUnreleased, unreleased, 2 entries)

# What broke between 1.4.0 and 2.1.0?
for r in cl.diff("1.4.0", "2.1.0"):
    for entry in r.breaking_changes:
        print(f"v{r.version}: {entry.text}")

Install

pip install patchnotes

Requires Python 3.10+.

Usage

Parse

import patchnotes

# From a file
cl = patchnotes.parse_file("CHANGELOG.md")

# From a string
cl = patchnotes.parse(raw_text)

# From a URL (e.g. raw GitHub)
cl = patchnotes.Changelog.from_url(
    "https://raw.githubusercontent.com/user/repo/main/CHANGELOG.md"
)

Access releases

cl.latest()               # highest versioned release
cl.unreleased()           # [Unreleased] block, or None
cl.get_version("2.0.0")   # specific version, or None
cl.releases               # all Release objects, in file order

Query entries

r = cl.get_version("2.0.0")

r.entries          # all Entry objects
r.by_type          # dict: {"Breaking": [...], "Added": [...], ...}
r.breaking_changes # shortcut: Breaking + Removed entries
r.yanked           # bool
r.release_date     # datetime.date or None

Diff and history

# All releases strictly between 1.4.0 (exclusive) and 2.1.0 (inclusive)
releases = cl.diff("1.4.0", "2.1.0")

# All releases newer than a version (includes Unreleased)
releases = cl.since_version("1.4.0")

# Every breaking change across the entire changelog
for version, entry in cl.all_breaking_changes():
    print(f"v{version}: {entry.text}")

Serialize

cl.to_dict()     # plain Python dict, JSON-safe
cl.to_json()     # JSON string (indent=2 by default)
cl.to_json(indent=4)

CLI

# Summary of all releases
patchnotes CHANGELOG.md

# Latest release
patchnotes CHANGELOG.md latest

# Unreleased changes
patchnotes CHANGELOG.md unreleased

# Specific version
patchnotes CHANGELOG.md show 2.0.0

# Diff between versions
patchnotes CHANGELOG.md diff 1.4.0 2.1.0

# All breaking changes
patchnotes CHANGELOG.md breaking

# Dump as JSON
patchnotes CHANGELOG.md json

Data model

Changelog
├── title: str
├── description: str
├── releases: list[Release]
│   ├── version: str
│   ├── release_date: date | None
│   ├── is_unreleased: bool
│   ├── yanked: bool
│   ├── entries: list[Entry]
│   │   ├── text: str
│   │   └── change_type: ChangeType
│   ├── by_type → dict[str, list[Entry]]
│   └── breaking_changes → list[Entry]
├── latest() → Release | None
├── unreleased() → Release | None
├── get_version(v) → Release | None
├── since_version(v) → list[Release]
├── diff(from, to) → list[Release]
├── all_breaking_changes() → list[tuple[str, Entry]]
├── to_dict() → dict
├── to_json() → str
└── from_url(url) → Changelog

ChangeType values: Added, Changed, Deprecated, Removed, Fixed, Security, Breaking

Changelog format

patchnotes parses the Keep a Changelog spec:

# Project Name

## [Unreleased]

### Added
- New feature

## [1.2.0] - 2024-11-15

### Breaking
- Renamed `foo()` to `bar()`

### Fixed
- Some bug

## [1.1.0] - 2024-09-01 [YANKED]

### Security
- Patched CVE-2024-1234

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

patchnotes-1.0.0.tar.gz (9.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

patchnotes-1.0.0-py3-none-any.whl (8.6 kB view details)

Uploaded Python 3

File details

Details for the file patchnotes-1.0.0.tar.gz.

File metadata

  • Download URL: patchnotes-1.0.0.tar.gz
  • Upload date:
  • Size: 9.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for patchnotes-1.0.0.tar.gz
Algorithm Hash digest
SHA256 9bab1cde1eb5f9af3fdecbc007ab6ce32dfb7fdacaddca792735689af1108189
MD5 d891ff0a72e20f4547cca237bd6ee5fa
BLAKE2b-256 8946ff502f6cdb1dad3c652768ee6f148e963f2e38e1a824fa6d26a22aead661

See more details on using hashes here.

File details

Details for the file patchnotes-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: patchnotes-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 8.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for patchnotes-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 dfd458498f07e7b4e0b159ea5d71ecb14ab5d535ce10f324f627640897edf446
MD5 caf5617d88605f18bc6dc52bce1ae401
BLAKE2b-256 d9fba6a89920ba503f9653f9f03aaabc906d5672bfa8c26649069dc0c9d25311

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page