A modern Python SDK for Bhagavad Gita.
Project description
OpenGita
Project Overview
OpenGita is a modern, high-performance, offline-first Python SDK for accessing Bhagavad Gita verses, chapters, translations, and commentaries. Designed for publication on GitHub and PyPI, OpenGita enables developers to build application integrations, educational platforms, and bots with structured Gita data.
The library uses a compiler-style build process where the raw dataset is parsed, validated, normalized, and pre-indexed. When installed, it loads the database exactly once into a thread-safe in-memory cache, offering zero-latency lookups without internet dependencies, databases, or API requirements.
Features
- ๐ถ 100% Offline-First: Built-in processed dataset. Zero network requests, databases, or cloud resources required.
- โก Zero IO Overhead: The dataset is loaded and validated exactly once using a thread-safe singleton cache.
- ๐ก๏ธ Pydantic v2 Types: Strict compile-time and runtime type checking for all domain entities. No dictionaries or generic maps returned.
- ๐ Rich Annotations: Includes 18 chapters, 701 canonical verses, and 18 pushpikas (chapter colophons).
- โ๏ธ Diverse Commentaries: Leverages translations and commentaries from 22 distinct scholars (e.g. Adi Shankaracharya, Swami Sivananda, Ramanujacharya, and Swami Chinmayananda).
- ๐ Reverse Indexing: Pre-built token-based inverted search index mapping words to verse boundaries.
Why OpenGita?
Traditional Gita APIs require constant network connectivity, suffer from latency issues, and feature unstructured, error-prone JSON responses. OpenGita solves these problems:
- Developer Experience: Auto-completion, docstrings, type hinting, and strict Pydantic schemas out of the box.
- Speed & Efficiency: Ideal for serverless, edge computing, mobile, or offline applications, executing in sub-millisecond times.
- Data Quality: Cleans whitespace, corrects numbering, and removes placeholder "did not comment" lines.
Installation
Install OpenGita from PyPI:
pip install opengita
Quick Start
from opengita import Gita
# Initialize client (loads and validates dataset in memory once)
gita = Gita()
# 1. Fetch random canonical verse
r = gita.random()
print(f"Random Verse: {r.id}")
print(r.slok)
# 2. Get specific verse (Chapter 2, Verse 47)
v = gita.verse(2, 47)
print(f"\nVerse {v.id}: {v.slok}")
print(f"English Translation: {v.translations[0].description}")
# 3. Get Chapter summary
ch = gita.chapter(2)
print(f"\nChapter {ch.number}: {ch.translation}")
print(f"Summary: {ch.summary['en']}")
Usage Examples
Retrieving a Specific Commentary
Get Swami Sivananda's commentary for Chapter 1, Verse 1:
from opengita import Gita
gita = Gita()
v = gita.verse(1, 1)
commentary = next(
(c.description for c in v.commentaries if c.author == "Swami Sivananda" and c.language == "en"),
"No commentary found."
)
print(commentary)
Retrieving Chapter Data
Get the original Sanskrit title and chapter meanings:
from opengita import Gita
gita = Gita()
ch = gita.chapter(12)
print(f"Sanskrit title: {ch.name}")
print(f"English meaning: {ch.meaning['en']}")
print(f"Hindi meaning: {ch.meaning['hi']}")
Project Architecture
Folder Structure
OpenGita/
โโโ dataset/
โ โโโ raw/ # Raw unprocessed JSON files
โ โโโ processed/ # Generated JSON outputs (chapters, verses, metadata, search index)
โโโ packages/
โ โโโ python/
โ โโโ opengita/
โ โโโ core/ # Settings & constants
โ โโโ exceptions/ # SDK domain exceptions
โ โโโ models/ # Pydantic v2 schemas
โ โโโ data/ # Packaged processed dataset
โ โโโ cache.py # Singleton cached memory state
โ โโโ loader.py # Loader & validator
โ โโโ randomizer.py # O(1) random verse selector
โ โโโ client.py # Developer interface class (Gita)
โโโ scripts/ # Normalization, validation & packaging scripts
โโโ tests/ # Unit tests
Dataset Pipeline
[raw/chapter] & [raw/slok]
โ
โผ (scripts/normalize_dataset.py)
[dataset/processed/*.json]
โ
โผ (scripts/validate_dataset.py)
[Integrity Verification Checks]
โ
โผ (scripts/package_data.py)
[opengita/data/*.json] (packaged local data)
SDK Design
The SDK follows a clean architecture pattern:
- Client (
Gita): Exposes methods (random,verse,chapter,statistics) to users. - DataLoader: Manages file retrieval and deserialization into domain models.
- GitaCache: A thread-safe singleton protecting in-memory dataset instances.
- Domain Models: Immutable Pydantic v2 models representation.
API Overview
Gita Client Methods
random() -> Verse: Returns a random canonical verse (excluding pushpikas).verse(chapter: int, verse: int) -> Verse: Lookups verse, raisingVerseNotFoundorChapterNotFoundif parameters are invalid.chapter(number: int) -> Chapter: Lookups chapter details, raisingChapterNotFoundif out of bounds.statistics() -> GitaStatistics: Exposes statistical details about translators, commentators, and file counts.
Example Output
Running python examples/example.py yields:
Initializing OpenGita SDK...
1. Fetching Chapter 2...
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ Chapter 2 โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Sanskrit Title: เคธเคพเคเคเฅเคฏเคฏเฅเค โ
โ Translation: Sankhya Yoga (Sฤnkhya Yog) โ
โ Meaning: Transcendental Knowledge โ
โ Verses Count: 72 โ
โ โ
โ Summary (English): The second chapter of the Bhagavad Gita is Sankhya Yoga. โ
โ This is the most important chapter of the Bhagavad Gita as Lord Krishna โ
โ condenses the teachings of the entire Gita in this chapter. โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Roadmap
- v0.1.0 (Current): Core SDK lookup functions, singleton cache, dataset processing.
- v0.2.0: In-memory text search engine (exact, partial, keyword) using pre-built search index.
- v0.3.0: Developer CLI using Typer and Rich formatting.
- v0.4.0: Local web server API support via FastAPI.
Contributing
We welcome contributions to OpenGita! Please see our Contributing Guide for setup details and code standards.
License
This project is licensed under the MIT License - see the LICENSE file for details.
FAQ
How is this offline?
The normalized JSON dataset is compiled and copied directly into the python package folder opengita/data/. When installed, it reads this packaged data using standard python importlib.resources.
Can I fetch pushpikas?
Yes! Standard verses are indexed 1 to verses_count. The chapter pushpika (colophon declaration) is available at verses_count + 1. Calling verse(1, 48) will return the pushpika for Chapter 1.
Acknowledgements
- Traditional scholars whose translations and commentaries are indexed in the raw dataset.
- The open-source Python community.
Author
- Name: Tejas Musale
- GitHub: @MusaleTejas
- LinkedIn: Tejas Musale
- Email: tejasmusale830@gmail.com
- Repository: GitHub Repository
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file opengita-0.1.0.tar.gz.
File metadata
- Download URL: opengita-0.1.0.tar.gz
- Upload date:
- Size: 8.6 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
405fe18d24d1e71f073e0099ba8954c2db9eebe4c8a04f81fe0869bfd2acf47f
|
|
| MD5 |
435985a182416a40819bc3ae1ffa7dfc
|
|
| BLAKE2b-256 |
93d338a97acacd52f3d2d2d3b58b46c1665edba9e4838240f6a58546b1c04362
|
File details
Details for the file opengita-0.1.0-py3-none-any.whl.
File metadata
- Download URL: opengita-0.1.0-py3-none-any.whl
- Upload date:
- Size: 9.0 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
41ab71df4e5ed2196394120278a8844c58c8429bfeb7f810122307906d7646ff
|
|
| MD5 |
898e98900b839ff5dc1dde207854ca61
|
|
| BLAKE2b-256 |
2e3bbd77a4893658bac5c344f53a69d920ae13c6988b478c39842f95c1640158
|