Skip to main content

A modern Python SDK for Bhagavad Gita.

Project description

OpenGita

PyPI version Python versions License: MIT Build Status Code Style


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:

  1. Developer Experience: Auto-completion, docstrings, type hinting, and strict Pydantic schemas out of the box.
  2. Speed & Efficiency: Ideal for serverless, edge computing, mobile, or offline applications, executing in sub-millisecond times.
  3. 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:

  1. Client (Gita): Exposes methods (random, verse, chapter, statistics) to users.
  2. DataLoader: Manages file retrieval and deserialization into domain models.
  3. GitaCache: A thread-safe singleton protecting in-memory dataset instances.
  4. 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, raising VerseNotFound or ChapterNotFound if parameters are invalid.
  • chapter(number: int) -> Chapter: Lookups chapter details, raising ChapterNotFound if 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

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

opengita-0.1.0.tar.gz (8.6 MB view details)

Uploaded Source

Built Distribution

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

opengita-0.1.0-py3-none-any.whl (9.0 MB view details)

Uploaded Python 3

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

Hashes for opengita-0.1.0.tar.gz
Algorithm Hash digest
SHA256 405fe18d24d1e71f073e0099ba8954c2db9eebe4c8a04f81fe0869bfd2acf47f
MD5 435985a182416a40819bc3ae1ffa7dfc
BLAKE2b-256 93d338a97acacd52f3d2d2d3b58b46c1665edba9e4838240f6a58546b1c04362

See more details on using hashes here.

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

Hashes for opengita-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 41ab71df4e5ed2196394120278a8844c58c8429bfeb7f810122307906d7646ff
MD5 898e98900b839ff5dc1dde207854ca61
BLAKE2b-256 2e3bbd77a4893658bac5c344f53a69d920ae13c6988b478c39842f95c1640158

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