Skip to main content

IndianConstitution

High-Performance Algorithmic Infrastructure & Deterministic Corpus Engine for the Constitution of India

PyPI Total Downloads CI Codecov License Python Typed Ruff DOI

CPU-Only Deterministic Execution · Strict Mypy Static Type Safety · Sub-Millisecond Inverted Index Search · Formal Exception Invariants · Zero Remote API Dependencies

Documentation  ·  Quickstart  ·  System Architecture  ·  Empirical Performance  ·  Citation


Executive Summary

indianconstitution is a production-grade Python infrastructure package engineered for high-throughput, deterministic algorithmic analysis of the Constitution of India. It provides formalized programmatic representations of all 464 articles, 12 schedules, the Preamble, landmark Supreme Court precedent mappings, amendment timelines, fundamental rights/duties cross-references, and multilingual translations — up to and including the Constitution (One Hundred and Sixth Amendment) Act, 2023.

Designed to serve as a foundational corpus infrastructure for legal NLP, Retrieval-Augmented Generation (RAG) pipelines, and civic data science, the engine operates under strict CPU-only execution guarantees with zero required network calls or cloud API keys.


Algorithmic Complexity & Guarantees

Operation Component Algorithm / Invariant Time Complexity Space Complexity
Article Lookup Hash map lookup by normalized string identifier $\mathcal{O}(1)$ $\mathcal{O}(N)$ memory
Keyword Search Tokenized inverted posting-list intersection $\mathcal{O}(K)$ for $K$ tokens $\mathcal{O}(V + P)$ index size
Fuzzy Matching Character ratio matrix calculation $\mathcal{O}(N \times M)$ $\mathcal{O}(1)$ dynamic RAM
Relational Graph Construction Directed citation adjacency graph assembly $\mathcal{O}(\vert V \vert + \vert E \vert)$ $\mathcal{O}(\vert V \vert + \vert E \vert)$ graph space
Amendment Text Delta Unified sequence difference computation $\mathcal{O}(L_1 \times L_2)$ $\mathcal{O}(L_1 + L_2)$ diff text
Corpus Integrity Verification Streaming cryptographic SHA-256 validation $\mathcal{O}(S)$ for $S$ bytes $\mathcal{O}(1)$ buffer

Hardware Requirements & CPU Constraints

indianconstitution strictly enforces hardware portability and zero-GPU execution dependencies:

  • Runtime Target: Runs on commodity x86_64 and ARM64 single-core or multi-core CPU dev machines.
  • Hardware Isolation: AI and semantic retrieval pipelines (indianconstitution[ai]) disable GPU acceleration paths (CUDA_VISIBLE_DEVICES="", torch.set_num_threads(...)) to guarantee deterministic offline CPU execution without GPU driver dependencies.
  • Memory Overhead: Instance heap footprint remains under 15 MB RAM, enabling microservice, serverless (AWS Lambda, Google Cloud Run), and embedded CLI execution.

System Architecture

┌─────────────────────────────────────────────────────────────────┐
│                        Public API Layer                         │
│   get_article() · search() · fuzzy_search() · get_constitution()│
└───────────────────────────────┬─────────────────────────────────┘
                                │
               ┌────────────────▼────────────────┐
               │    Constitution  (engine.py)     │
               │  Lazy-loading · Singleton cache  │
               └──┬──────────────┬───────────────┘
                  │              │
     ┌────────────▼───┐  ┌───────▼───────────┐  ┌──────────────────┐
     │  SearchEngine  │  │  ConstitutionGraph │  │    Exporter      │
     │ (inverted idx) │  │  (NetworkX graph)  │  │ JSON · CSV · MD  │
     └────────────────┘  └────────────────────┘  └──────────────────┘
                  │              │
     ┌────────────▼──────────────▼──────────────────┐
     │            Pydantic v2 Data Models           │
     │   Article · Part · Schedule · SearchResult   │
     │   CaseLaw · AmendmentEvent · DutyCrossRef    │
     └──────────────────────┬───────────────────────┘
                            │
     ┌──────────────────────▼───────────────────────┐
     │         Custom Typed Exception Hierarchy     │
     │  IndianConstitutionError (BaseException)     │
     │  ├── ArticleNotFoundError                    │
     │  ├── CorpusIntegrityError                    │
     │  ├── InvalidAmendmentRangeError              │
     │  ├── DependencyMissingError                  │
     │  └── UnsupportedFormatError                  │
     └──────────────────────────────────────────────┘

Quickstart

Installation

# Core package (zero external runtime dependencies)
pip install indianconstitution

# With network analysis & data science utilities (NetworkX, pandas)
pip install "indianconstitution[data]"

# With offline CPU semantic embeddings (sentence-transformers)
pip install "indianconstitution[ai]"

# Full installation suite
pip install "indianconstitution[all]"

Deterministic Python Usage

>>> from indianconstitution import get_article, search, get_constitution

>>> # Type-safe article retrieval (O(1) lookup)
>>> article = get_article("21A")
>>> article.number
'21A'
>>> article.title
'Right to Education'

>>> # Sub-millisecond inverted posting-list search
>>> results = search("equality before law", limit=3)
>>> [r.number for r in results]
['14', '15']

>>> # Full Constitution engine instance
>>> const = get_constitution()
>>> len(const) > 0
True

Formal Exception Invariants

The library enforces fail-fast error reporting through a strict exception hierarchy derived from IndianConstitutionError:

from indianconstitution import (
    Constitution,
    ArticleNotFoundError,
    InvalidAmendmentRangeError,
    UnsupportedFormatError,
)

const = Constitution()

# 1. Missing Article Access Guard
try:
    article = const.require_article("99999")
except ArticleNotFoundError as err:
    print(f"Article identifier missing: {err.article_number}")

# 2. Year Bound Invariant Check
try:
    diff = const.diff_amendment("21A", from_year=2026, to_year=2010)
except InvalidAmendmentRangeError as err:
    print(f"Invalid temporal range: {err.from_year} > {err.to_year}")

# 3. Export Specification Enforcement
try:
    const.export("unsupported_fmt", "output.dat")
except UnsupportedFormatError as err:
    print(f"Format rejected: {err.format_requested}")

Empirical Performance

Empirical execution benchmarks gathered via python scripts/benchmark.py over 1,000 iterations on a single CPU core:

Benchmark Target Samples p50 Latency p95 Latency p99 Latency Throughput (QPS)
Article Lookup (by num) 2,000 0.0002 ms 0.0003 ms 0.0004 ms 2,591,680 QPS
Inverted Index Keyword Search 1,000 0.0026 ms 0.0029 ms 0.0058 ms 255,180 QPS
Fuzzy Similarity Search 500 36.2227 ms 38.6790 ms 40.8080 ms 27.4 QPS
Graph Relational Traversal 1,000 0.0014 ms 0.0015 ms 0.0017 ms 653,295 QPS
Amendment Diff (Art 21A) 1,000 0.0147 ms 0.0158 ms 0.0210 ms 59,606 QPS
Graph Reconstruction 100 46.0691 ms 51.9408 ms 54.7579 ms 21.5 QPS

Verification & Quality Assurance Matrix

Every code modification and mathematical claim is verifiable via standard verification targets:

# 1. Static code quality analysis (Ruff)
ruff check src/indianconstitution

# 2. Code formatting verification (Ruff)
ruff format --check src/indianconstitution

# 3. Strict static type safety analysis (Mypy --strict)
mypy src/indianconstitution

# 4. Property-based & unit test suite (>90% coverage enforcement)
pytest

# 5. SHA-256 data integrity & schema validation
python scripts/validate_corpus.py

# 6. Local CPU empirical benchmark suite
python scripts/benchmark.py

Citation

If you incorporate indianconstitution into software systems, research papers, or legal informatics benchmarks, please cite:

@software{vikhram2026indianconstitution,
  author       = {S, Vikhram},
  title        = {{IndianConstitution: High-Performance Algorithmic Infrastructure
                   \& Deterministic Corpus Engine for the Constitution of India}},
  year         = {2026},
  version      = {1.5.2},
  publisher    = {PyPI},
  url          = {https://github.com/Vikhram-S/IndianConstitution},
  doi          = {10.5281/zenodo.18200429},
  license      = {Apache-2.0},
}

License

Copyright © 2026 Vikhram S. Distributed under the terms of the Apache License 2.0. See LICENSE.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

indianconstitution-1.5.2.tar.gz (151.7 kB view details)

Uploaded Source

Built Distribution

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

indianconstitution-1.5.2-py3-none-any.whl (143.2 kB view details)

Uploaded Python 3

File details

Details for the file indianconstitution-1.5.2.tar.gz.

File metadata

  • Download URL: indianconstitution-1.5.2.tar.gz
  • Upload date:
  • Size: 151.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for indianconstitution-1.5.2.tar.gz
Algorithm Hash digest
SHA256 2601048b371cd4d64b5040ce122cfc66d8e361fbde3384b6f80e2ade99d0b4ba
MD5 6bd00def07a54e054ba48b74ba961d11
BLAKE2b-256 dea52ddcd055ce35cc406af9b25633b001f8ad21d69e0ee31d55142df2cc0122

See more details on using hashes here.

Provenance

The following attestation bundles were made for indianconstitution-1.5.2.tar.gz:

Publisher: release.yml on Vikhram-S/IndianConstitution

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

File details

Details for the file indianconstitution-1.5.2-py3-none-any.whl.

File metadata

File hashes

Hashes for indianconstitution-1.5.2-py3-none-any.whl
Algorithm Hash digest
SHA256 b1b5b5aa60ed449fc081548ab5e880f461716e06c88b418e3b3dc6d9a294ddd9
MD5 0b300f5f966708bfee63942fdb7cbfd7
BLAKE2b-256 48438ca76070faa672a5d591a79d1c07cc775013ffcb41ecf73a08a4df3cfcd7

See more details on using hashes here.

Provenance

The following attestation bundles were made for indianconstitution-1.5.2-py3-none-any.whl:

Publisher: release.yml on Vikhram-S/IndianConstitution

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

Release history Release notifications | RSS feed

1.5.3

2 files

This release

1.5.2 This release

2 files

1.5.1

2 files

1.5.0

2 files

1.4.0

2 files

1.3.1

2 files

1.3.0

2 files

1.2.0

2 files

1.1.0

2 files

1.0.1

2 files

0.8

2 files

0.7

2 files

0.6.1

2 files

0.6.0

2 files

0.5.9

2 files

0.5.8

2 files

0.5.7

2 files

0.5.6.1

2 files

0.5.6

2 files

0.5.5

2 files

0.5.4

2 files

0.5.3

2 files

0.5.2

2 files

0.5.1

2 files

0.5

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page