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, orpyproject.tomldependency groups - 📦 Resolve import names to installed distributions (handling name
mismatches like
yaml→PyYAML,cv2→opencv-python,sklearn→scikit-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(useomit="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.
Metadata
Release files for grateful-py 0.2.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| grateful_py-0.2.1.tar.gz | 27.5 kB | Without provenance | Details for grateful_py-0.2.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| grateful_py-0.2.1-py3-none-any.whl | Python 3 | none | any | Details for grateful_py-0.2.1-py3-none-any.whl |
Total release size: 54.4 kB
Release files / grateful_py-0.2.1.tar.gz
| Download URL | grateful_py-0.2.1.tar.gz |
|---|---|
| Size | 27.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
eed22bc55372ebc117804a230ff501b16365116a62134d0b4b4fd64110dd91f1
|
|
BLAKE2b-256 checksum How to use checksums |
ea62d9b2553d80e0548c0a11bebb6ccf4882e3b918bd696713577f5e2085aec2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.10.16
|
Release files / grateful_py-0.2.1-py3-none-any.whl
| Download URL | grateful_py-0.2.1-py3-none-any.whl |
|---|---|
| Size | 26.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b4159db5738fb11a5a8996da929d72a980daa9635993ef0d663cc8b1aa0fafc9
|
|
BLAKE2b-256 checksum How to use checksums |
70d4de6e60dee96fb0e4368c0fda9623187761e51d9c9fb5958f1b39663ea7d9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.10.16
|
Security for grateful-py 0.2.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.