Skip to main content

NIOBIUM: Nadia's Image Occlusion Booster Is UnManned - A CLI tool for extracting text and image-occlusion-style notes from images and PDFs for Anki

Project description

PyPI - Version

NIOBIUM: Nadia's Image Occlusion Booster Is UnManned

NIOBIUM is a small CLI tool for extracting text and image-occlusion-style notes from images and PDFs, and for preparing Anki-compatible outputs (via AnkiConnect or by creating an .apkg). This README shows common usages and examples for the command-line interface.

Trivia: What the actual heck is niobium?

Niobium is a stealthy gray metal that is absurdly strong, feather‑light and allergic to corrosion. Mostly mined in Brazil and Canada, it moonlights in super‑alloys for jet engines and superconducting MRI magnets. It even hides in the capacitors inside your phone and laptop.

So next time you're on a flight, fiddling with your phone on the way to an MRI conference, tip your hat to niobium, OR just give this repo a ⭐️.

Installation

Using pip

pip install anki-niobium

Using uv (faster alternative)

uv pip install anki-niobium

From source

git clone https://github.com/agahkarakuzu/niobium.git
cd niobium
pip install -e .

Requirements

  • Python 3.8 or higher
  • All dependencies are automatically installed with the package

Quick overview

The main entry point is the niobium command. It exposes a few mutually-exclusive input modes and a few mutually-exclusive output modes.

Inputs (one required):

  • -i, --image — absolute path to a single image file
  • -dir, --directory — directory containing multiple images
  • -pin, --single-pdf — absolute path to a single PDF

Outputs (one required):

  • -deck, --deck-name — name of the Anki deck where notes will be pushed (requires AnkiConnect)
  • -pout, --pdf-img-out — output directory where images extracted from a PDF will be saved
  • -apkg, --apkg-out — output directory where a generated .apkg will be saved

Other useful flags:

  • -ioid, --io-model-id — ID of the built-in Image Occlusion model in Anki (optional, used with --apkg-out)
  • -m, --merge-rects — whether to merge nearby detected rectangles (default: True)
  • -mx, --merge-lim-x — horizontal merging threshold in pixels (default: 10)
  • -my, --merge-lim-y — vertical merging threshold in pixels (default: 10)
  • -l, --langs — comma-separated OCR languages (default: en)
  • -g, --gpu — GPU index to use, or -1 for CPU only (default: -1)
  • -hdr, --add-header — add filename as a header (default: False)
  • -basic, --basic-type — create basic Anki cards instead of image-occlusion notes (default: False)

Run niobium -h to see the help text with the current arguments.

Examples

Below are some concrete example commands (assumes you're in the project root and using zsh/bash):

  1. ⭐️ Run OCR and push image-occlusion notes to an Anki deck (via AnkiConnect)

This processes all images under a directory and pushes notes to the Anki deck named MyStudyDeck.

niobium --directory /absolute/path/to/images --deck-name MyStudyDeck

Notes:

  • You may specify a deck name that doesn't yet exist; you'll be prompted to create it.
  • Anki must be running with the AnkiConnect add-on enabled.
  • The tool will detect text and create image-occlusion notes from detected regions.
  1. Extract images from a single PDF

This extracts embedded images from lecture.pdf into ./out_images.

niobium --single-pdf /absolute/path/to/lecture.pdf --pdf-img-out /absolute/path/to/out_images

Important: --single-pdf is required when using --pdf-img-out.

  1. Produce an .apkg file (offline export, NOT TESTED)

This processes a directory and writes an .apkg bundle suitable for import into Anki without requiring AnkiConnect at runtime.

niobium --directory /absolute/path/to/images --apkg-out /absolute/path/to/output_dir

Optional: include the Image Occlusion model id if you want the built-in model referenced in the package:

niobium --directory /absolute/path/to/images --apkg-out /absolute/path/to/output_dir --io-model-id 12345
  1. Create basic (front/back) Anki cards instead of image-occlusion notes
niobium --directory /absolute/path/to/images --deck-name MyStudyDeck --basic-type True

This comes in handy when you have a bunch of images in a folder (may be extracted from a PDF, see (2) above), and would like to create Q&A for each one of them.

  1. Tweak rectangle merging and OCR languages

If bounding boxes are too fragmented, increase the merge thresholds. To OCR multiple languages, provide a comma-separated list.

niobium --directory /absolute/path/to/images --deck-name MyStudyDeck --merge-lim-x 20 --merge-lim-y 20 --langs en,fr

Note: Rectangle merging and other heuristics are experimental. Nearby occlusion boxes may be merged unintentionally, or distinct boxes may remain separate. Adjust --merge-lim-x/--merge-lim-y or disable merging with --merge-rects to change the behavior.

If you come up with a more robust approach to this, feel free to send a PR!

  1. GPU usage

Pass --gpu 0 to attempt to use GPU 0. The default -1 runs on CPU.

niobium --directory /abs/path/to/images --deck-name MyStudyDeck --gpu 0

Common workflows

  • Automatic creation of image-occlusion notes and push to Anki:
    • --directory + --deck-name (Anki must be running with anki-connect installed)
    • --single-pdf + --deck-name (Anki must be running with anki-connect installed)
  • Quick extraction from a PDF for manual review:
    • --single-pdf + --pdf-img-out

Troubleshooting

  • If AnkiConnect calls fail, confirm Anki is running and AnkiConnect is installed and enabled.
  • If OCR quality is poor, try adding the proper language code with --langs (e.g., en,es) and ensure Tesseract language packs are installed.
  • If many small boxes are produced, increase --merge-lim-x/--merge-lim-y or set --merge-rects False to disable merging.

Development

Setting up for development

git clone https://github.com/agahkarakuzu/niobium.git
cd niobium
pip install -e .

Running tests

The package includes automated tests that run on each push via GitHub Actions. You can test locally:

# Test the CLI is available
niobium -h

# Test import
python -c "from niobium.cli import main; print('Import successful')"

Project structure

  • niobium/cli.py - Main CLI entry point with argument parsing
  • niobium/io.py - Core I/O helpers and OCR functionality
  • pyproject.toml - Package configuration and dependencies

Contributing

If you'd like to contribute, open an issue or submit a pull request.

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

anki_niobium-0.2.4.tar.gz (24.4 kB view details)

Uploaded Source

Built Distribution

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

anki_niobium-0.2.4-py3-none-any.whl (23.7 kB view details)

Uploaded Python 3

File details

Details for the file anki_niobium-0.2.4.tar.gz.

File metadata

  • Download URL: anki_niobium-0.2.4.tar.gz
  • Upload date:
  • Size: 24.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for anki_niobium-0.2.4.tar.gz
Algorithm Hash digest
SHA256 556a17f4ab1ed9f07a367587898017ea7f442d984d509943e6030482d7cbc18e
MD5 6f2ad320b4abc06b51dd7b60e6988822
BLAKE2b-256 b6805fc777e07e2c2a190e2e626c6981456d90a49b780c9cf35c66134415bd29

See more details on using hashes here.

Provenance

The following attestation bundles were made for anki_niobium-0.2.4.tar.gz:

Publisher: publish-pypi.yml on agahkarakuzu/niobium

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file anki_niobium-0.2.4-py3-none-any.whl.

File metadata

  • Download URL: anki_niobium-0.2.4-py3-none-any.whl
  • Upload date:
  • Size: 23.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for anki_niobium-0.2.4-py3-none-any.whl
Algorithm Hash digest
SHA256 74948bdab81ec30e217dae107c2cfab37092b8586fb107e22a8b5a9db3c03a51
MD5 711bed6c6f389375c373419c2ff43dae
BLAKE2b-256 ef8a6e518eeb615de620bbde604841022feccdb6a16cf0dd2064484757033261

See more details on using hashes here.

Provenance

The following attestation bundles were made for anki_niobium-0.2.4-py3-none-any.whl:

Publisher: publish-pypi.yml on agahkarakuzu/niobium

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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