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.0.tar.gz (27.3 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.0-py3-none-any.whl (26.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: grateful_py-0.2.0.tar.gz
  • Upload date:
  • Size: 27.3 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.0.tar.gz
Algorithm Hash digest
SHA256 20078067d6a3eaac9786bf8d19cc10d1b48526528275a9b2457d1e12c06946ff
MD5 91625b24cee185b975b7bef807e463d2
BLAKE2b-256 7716c808f8f376c80c905fdc9a121e24c374c94e95b28dc99837994701f9bb65

See more details on using hashes here.

File details

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

File metadata

  • Download URL: grateful_py-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 26.8 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 cd62f8e581704e74f1979da22fac0a38f7988ab1e16ca77fe624f5e04ce0a4db
MD5 ddf386fd47fc201eb5350d68401c8157
BLAKE2b-256 867acebe852e36b73534319a5a3ab2f287be733c2f40c08ba3e90f46c437ecb5

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