IndianConstitution
High-Performance Algorithmic Infrastructure & Deterministic Corpus Engine for the Constitution of India
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.
Metadata
Release files for indianconstitution 1.5.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| indianconstitution-1.5.3.tar.gz | 152.1 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| indianconstitution-1.5.3-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 295.6 kB
Release files / indianconstitution-1.5.3.tar.gz
| Download URL | indianconstitution-1.5.3.tar.gz |
|---|---|
| Size | 152.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6ec56984333c08e3a0da433c78d5e8ff1b4905a1a94f719ff7e7de9924667284
|
|
BLAKE2b-256 checksum How to use checksums |
34ad94f01e655210fef19ee9a05bd390834b43619c6014180e7283270cb52c15
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 31, 2026.
Transparency logRelease files / indianconstitution-1.5.3-py3-none-any.whl
| Download URL | indianconstitution-1.5.3-py3-none-any.whl |
|---|---|
| Size | 143.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
3dbcfc509a77ac6d7da83100d3ff0fbbea18c6df1c8d649586dc629304f44f80
|
|
BLAKE2b-256 checksum How to use checksums |
601dda2cf4b43ada19fff523b6ab5a2bd28eb7f4f6426f47d137cdce0022338c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 31, 2026.
Transparency log