Skip to main content

grateful-py README

grateful-py 🐍

Automatic citation generation for Python projects.

grateful-py is a Python port of the R package grateful: it scans a project (or the current session, or pyproject.toml), resolves the packages actually used, pulls their metadata, and generates formatted citations (BibTeX, Markdown, JSON, plain text, HTML, and — via Pandoc — Word/PDF/LaTeX).

Features

  • 🔍 Detect imported packages via AST scanning of a project, the current session (sys.modules), a single file, or pyproject.toml dependency groups
  • 📦 Resolve import names to installed distributions (handling name mismatches like yamlPyYAML, cv2opencv-python, sklearnscikit-learn)
  • 🌳 Optionally expand to the full transitive dependency closure
  • 🧠 Extract metadata via importlib.metadata, with unique BibTeX citekeys
  • 📝 Generate citations as a BibTeX file, CSV, Markdown, JSON, a plain-text paragraph, an HTML report, or — with Pandoc installed — DOCX/PDF/LaTeX with real CSL-styled bibliographies
  • 🎨 Fetch any CSL citation style (APA, PeerJ, …) by name
  • 🚀 CLI (grateful-py) + Python API
  • ⚙️ Configurable omit (use omit="none" to include all packages), skip_missing, and dependency-group scanning

Installation

pip install grateful_py

Word/PDF/LaTeX report generation additionally requires Pandoc to be installed and on PATH. All other formats (bib, csv, json, txt, md, html) work without it.

Usage

CLI

# List packages detected in the current project
grateful-py scan .

# Generate a Markdown citation report (grateful-report.md + grateful-refs.bib)
grateful-py cite . --out-dir .

# Generate a Word document, styled with a specific CSL citation style
# (requires Pandoc)
grateful-py cite . --out-format docx --citation-style apa --out-dir .

# Just the inline citation paragraph
grateful-py cite . --output paragraph

# Only packages declared in pyproject.toml
grateful-py scan . --pkgs pyproject --groups dependencies

# Download a CSL style file
grateful-py csl peerj --out-dir .

Run grateful-py cite --help / grateful-py scan --help for the full list of options (--omit, --include-dependencies, --skip-missing, --pkgs, …).

Python API

grateful-py’s API mirrors R grateful’s function names:

R grateful grateful-py
scan_packages() scan_packages()
get_pkgs_info() get_pkgs_info()
get_citations() get_citations()
cite_packages() cite_packages()
get_csl() get_csl()
nocite_references() nocite_references()
import grateful_py as g

# Detect packages used in a project
packages = g.scan_packages(".")

# Same, but scan the current session (sys.modules) instead of files on disk
packages = g.scan_packages(pkgs="session")

# Or read dependencies straight from pyproject.toml
packages = g.scan_packages(".", pkgs="pyproject", groups=["dependencies"])

# Get full citation metadata + write a BibTeX file
citations = g.get_pkgs_info(".", out_dir=".")

# Just an inline citation sentence, for embedding in a paper/report
print(g.cite_packages(".", output="paragraph"))
# "We used Python version 3.12.2 [@python] and the following Python
#  packages: numpy v1.26.4 [@numpy], pandas v2.2.1 [@pandas]."

# A table of package/version/citation, e.g. for a Quarto/Jupyter document
g.cite_packages(".", output="table")

# A full report file — natively for bib/csv/json/txt/md/html, via Pandoc for
# docx/pdf/tex-fragment/tex-document/Rmd
g.cite_packages(".", output="file", out_format="csv", out_dir=".")

# Fetch a CSL citation style and use it when rendering
g.get_csl("apa", out_dir=".")
g.cite_packages(".", out_format="docx", citation_style="apa", out_dir=".")

# Force specific citekeys into a references list without an inline mention
print(g.nocite_references(["numpy", "pandas"]))

Development

pip install -e ".[test]"
pytest

Acknowledgments

This project is inspired by the R package grateful by Francisco Rodríguez-Sánchez (Pakillo). grateful-py aims to bring the same spirit of reproducibility, transparency, and scholarly respect for software authors to the Python ecosystem.

Download files

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

Source Distribution

grateful_py-0.2.1.tar.gz (27.5 kB view details)

Uploaded Source

Built Distribution

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

grateful_py-0.2.1-py3-none-any.whl (26.9 kB view details)

Uploaded Python 3

File details

Details for the file grateful_py-0.2.1.tar.gz.

File metadata

  • Download URL: grateful_py-0.2.1.tar.gz
  • Upload date:
  • Size: 27.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.16

File hashes

Hashes for grateful_py-0.2.1.tar.gz
Algorithm Hash digest
SHA256 eed22bc55372ebc117804a230ff501b16365116a62134d0b4b4fd64110dd91f1
MD5 2132b4ca0532f410090705429f0e2d34
BLAKE2b-256 ea62d9b2553d80e0548c0a11bebb6ccf4882e3b918bd696713577f5e2085aec2

See more details on using hashes here.

File details

Details for the file grateful_py-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: grateful_py-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 26.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.16

File hashes

Hashes for grateful_py-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b4159db5738fb11a5a8996da929d72a980daa9635993ef0d663cc8b1aa0fafc9
MD5 5c263e90e8798d8746cc5c0fae174cfc
BLAKE2b-256 70d4de6e60dee96fb0e4368c0fda9623187761e51d9c9fb5958f1b39663ea7d9

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