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.
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 indianconstitution-1.5.3.tar.gz.
File metadata
- Download URL: indianconstitution-1.5.3.tar.gz
- Upload date:
- Size: 152.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6ec56984333c08e3a0da433c78d5e8ff1b4905a1a94f719ff7e7de9924667284
|
|
| MD5 |
b27ff2dbb98886ddb564705246f9aeb2
|
|
| BLAKE2b-256 |
34ad94f01e655210fef19ee9a05bd390834b43619c6014180e7283270cb52c15
|
Provenance
The following attestation bundles were made for indianconstitution-1.5.3.tar.gz:
Publisher:
release.yml on Vikhram-S/IndianConstitution
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
indianconstitution-1.5.3.tar.gz -
Subject digest:
6ec56984333c08e3a0da433c78d5e8ff1b4905a1a94f719ff7e7de9924667284 - Sigstore transparency entry: 2661636147
- Sigstore integration time:
-
Permalink:
Vikhram-S/IndianConstitution@42482fb6c79e073f227c7746ef20728d0778afd8 -
Branch / Tag:
refs/tags/v1.5.3 - Owner: https://github.com/Vikhram-S
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@42482fb6c79e073f227c7746ef20728d0778afd8 -
Trigger Event:
push
-
Statement type:
File details
Details for the file indianconstitution-1.5.3-py3-none-any.whl.
File metadata
- Download URL: indianconstitution-1.5.3-py3-none-any.whl
- Upload date:
- Size: 143.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3dbcfc509a77ac6d7da83100d3ff0fbbea18c6df1c8d649586dc629304f44f80
|
|
| MD5 |
e3d3026a4b0a60428477ac80ef54c643
|
|
| BLAKE2b-256 |
601dda2cf4b43ada19fff523b6ab5a2bd28eb7f4f6426f47d137cdce0022338c
|
Provenance
The following attestation bundles were made for indianconstitution-1.5.3-py3-none-any.whl:
Publisher:
release.yml on Vikhram-S/IndianConstitution
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
indianconstitution-1.5.3-py3-none-any.whl -
Subject digest:
3dbcfc509a77ac6d7da83100d3ff0fbbea18c6df1c8d649586dc629304f44f80 - Sigstore transparency entry: 2661636277
- Sigstore integration time:
-
Permalink:
Vikhram-S/IndianConstitution@42482fb6c79e073f227c7746ef20728d0778afd8 -
Branch / Tag:
refs/tags/v1.5.3 - Owner: https://github.com/Vikhram-S
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@42482fb6c79e073f227c7746ef20728d0778afd8 -
Trigger Event:
push
-
Statement type: