pyvault 1.0.3 · Tool for Python
Your Python project, as a knowledge graph
pyvault reads a Python project with Python's own parser and writes an Obsidian vault: a Markdown note for every module, class and function, in the project's own folders. Notes link to each other with [[wiki links]], so classes point to the classes they inherit from and modules to what they contain.
Free software (MIT) · Python 3.9 or newer · no dependencies
- pyvault shop vaultreads every .py file
- One note eachmodules, classes, functions
- [[links]]a graph in Obsidian
Examples
What sets it apart
Each example is a complete script, run with pyvault 1.0.3. The output is what it printed.
A project in, a vault out
The command gets the project and the folder for the vault. The notes follow the project's folders: shop/billing/invoice.py becomes billing/invoice.md and a folder for its classes.
# Turn the project in shop/ into an Obsidian vault in vault/ rm -rf vault pyvault shop vault > /dev/null echo "The notes:" (cd vault && find . -name '*.md' | LC_ALL=C sort | sed 's|^\./| |')
The notes: billing/invoice.md billing/invoice/CreditNote.md billing/invoice/CreditNote/total.md billing/invoice/Invoice.md billing/invoice/Invoice/__init__.md billing/invoice/Invoice/add.md billing/invoice/Invoice/total.md billing/invoice/discount.md billing/invoice/imports.md models.md models/Customer.md models/Customer/__init__.md models/Product.md models/Product/__init__.md
Notes that link
A module lists its functions and classes; a class names its parent, methods and docstring; a function its arguments.
"""Invoices: lines, discounts and totals.""" from shop.models import Customer, Product def discount(customer): """10% off for VIP customers.""" return 0.10 if customer.vip else 0.0 class Invoice: def __init__(self, customer): self.customer = customer self.lines = [] def add(self, product, units=1): self.lines.append((product, units)) def total(self): """Sum of the lines, less the customer's discount.""" gross = sum(p.price * u for p, u in self.lines) return round(gross * (1 - discount(self.customer))) class CreditNote(Invoice): """An invoice that gives money back.""" def total(self): return -super().total()
# A module, a class that inherits, and a function with its docstring. # [[links]] point to other notes, the way Obsidian links them. rm -rf vault pyvault shop vault > /dev/null for note in billing/invoice billing/invoice/CreditNote billing/invoice/discount; do echo "==> vault/$note.md" cat "vault/$note.md" echo done
==> vault/billing/invoice.md # Module `invoice.py` #module **Path**: `billing/invoice.py` ## Functions: - [[billing/invoice/discount]] ## Classes: - [[billing/invoice/Invoice]] - [[billing/invoice/CreditNote]] ==> vault/billing/invoice/CreditNote.md # Class `CreditNote` #class **File**: `billing/invoice.py` ## Docstring: An invoice that gives money back. ## Inherits from: - [[billing/invoice/Invoice]] ## Methods: - [[billing/invoice/CreditNote/total]] ## Properties: - None ==> vault/billing/invoice/discount.md # Function `discount` #method **File**: `billing/invoice.py` ## Arguments: - `customer` ## Docstring: 10% off for VIP customers.
Install
Run it on a project
1. Install it
With pip.
pip install divengine-pyvault==1.0.3
2. Make a vault
Give it a project and an output folder, then open the folder as a vault in Obsidian.
pyvault ./my_project ./my_vault
The sample project, the scripts and the commands to run them again with pyvault 1.0.3 are in the site's repository.