Skip to main content

Convert MySQL tables into Obsidian notes and Bases .base files

Project description

MySQL → Obsidian Bases (CLI)

Convert rows from a MySQL table into Obsidian notes with YAML frontmatter and generate a corresponding .base file for the Bases core plugin.

Features

  • Connects to MySQL using CLI flags
  • Exports each row to a Markdown file with properly-typed frontmatter
  • Infers property types from MySQL schema (numbers, dates, datetimes, booleans, text)
  • Generates a .base file that filters to the exported folder and provides a default Table view
  • Idempotent by default (overwrites files with the same name)

Install

python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
pip install -e .

Usage

Preferred (console script):

mysql-to-bases \
  --host 127.0.0.1 \
  --user root \
  --password secret \
  --database mydb \
  --table books \
  --output /absolute/path/to/output \
  --id-column id \
  --title-column title

Export all tables:

mysql-to-bases \
  --host 127.0.0.1 \
  --user root \
  --password secret \
  --database mydb \
  --all-tables

Or via module:

python -m mysql_to_obsidian_bases --help
  • You must specify either --table <name> or --all-tables.
  • --host/--user/--password/--database/--port: MySQL connection
  • --table: Table name to export
  • --all-tables: Export every base table found in the database
  • --output: Output directory for the base folder (default: ./output/<table>-base)
  • --id-column: Column used for filenames (default: id or first column)
  • --title-column: Column used as the H1 title inside the note (optional)

After running, you'll have:

  • output/<table>-base/notes/ with one .md file per row
  • output/<table>-base/<table>.base with a default Table view filtered to the above folder

Example

mysql-to-bases \
  --host 127.0.0.1 --user root --password secret --database library \
  --table books --id-column id --title-column title

This creates something like:

output/books-base/
  books.base
  notes/
    1.md
    the-hitchhikers-guide-to-the-galaxy.md
    ...

Tip: Move the generated folder into your Obsidian vault. The .base file includes a filter that limits results to the notes/ subfolder.

Notes on Types and Formatting

  • Dates (DATE) are formatted as YYYY-MM-DD
  • Datetimes (DATETIME, TIMESTAMP) are formatted as YYYY-MM-DD HH:mm:ss
  • Booleans (TINYINT(1)) become true/false
  • Numbers remain numbers
  • Strings are emitted as YAML strings when necessary

The .base file sets a global filter file.inFolder("<table>-base/notes") to scope the view to the generated notes.

Stretch Goals (not yet implemented)

  • --query to use a custom SQL query (type inference is trickier when not tied to a single table)
  • Incremental updates (append-only or merge strategies)
  • Per-column type overrides via a config file

Development

Project structure:

mysql_to_obsidian_bases/
  __init__.py
  __main__.py
  cli.py
  mysql_utils.py
  type_inference.py
  markdown_generator.py
  base_generator.py

Run locally:

mysql-to-bases --help

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

mysql_to_obsidian_bases-0.1.0.tar.gz (19.6 kB view details)

Uploaded Source

Built Distribution

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

mysql_to_obsidian_bases-0.1.0-py3-none-any.whl (19.4 kB view details)

Uploaded Python 3

File details

Details for the file mysql_to_obsidian_bases-0.1.0.tar.gz.

File metadata

  • Download URL: mysql_to_obsidian_bases-0.1.0.tar.gz
  • Upload date:
  • Size: 19.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.2

File hashes

Hashes for mysql_to_obsidian_bases-0.1.0.tar.gz
Algorithm Hash digest
SHA256 0587584ab2de95bb185ad4c0f8f94db2b56efd4989211886b5c4a094ea9e8d96
MD5 1e42f1fd9b89999ff8ff7ada06a7d0e2
BLAKE2b-256 ba98234739eb74902753701f45fb8d758398028fd80de13be192c001d556dfcc

See more details on using hashes here.

File details

Details for the file mysql_to_obsidian_bases-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for mysql_to_obsidian_bases-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c89de235f500c8266b437ca916db410bb539da3f3d211c7e1392d58e36d6721b
MD5 117f78f5b5266b6a1a974359ea79e8f9
BLAKE2b-256 489758cc2e6e325c573599e4d55b0728ca0be427a48a6711501258e5c3d985dd

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