The complete Sahih al-Bukhari β 7,277 hadiths, full Arabic & English.
One repo Β· one dataset Β· published on both npm and PyPI.
| Feature | Details | |
|---|---|---|
| π | Complete Collection | All 7,277 authentic hadiths from Sahih al-Bukhari |
| π | Bilingual | Full Arabic text + English translation for every hadith |
| π | Chapters | 4,000+ chapters with Arabic & English names |
| β‘ | Tiny Install | ~3KB package β data loaded from CDN on demand |
| π | Full-text Search | Search English text and narrator names instantly |
| π₯οΈ | CLI | Terminal access with Arabic/English/both flags |
| βοΈ | React Hook | One command generates useBukhari() in your project |
| π | Python | Identical API β same method names as the npm package |
| π | TypeScript | Full type definitions, zero @types package needed |
| π§ | Zero Config | Works out of the box everywhere |
| ποΈ | One Dataset | bin/bukhari.json shared by both JS and Python |
| JavaScript / Node.js | Python |
# local (for projects)
npm install sahih-al-bukhari
# global (for CLI)
npm install -g sahih-al-bukhari |
# local (for projects)
pip install sahih-al-bukhari
# global CLI is included automatically |
// CommonJS β require()
const bukhari = require("sahih-al-bukhari");
// ESM β import
import bukhari from "sahih-al-bukhari";
// Get by ID
bukhari.get(1); // β Hadith
// Get by chapter
bukhari.getByChapter(1); // β Hadith[]
// Full-text search
bukhari.search("prayer"); // β Hadith[]
// Random
bukhari.getRandom(); // β Hadith
// Index access
bukhari[0]; // β Hadith (first)
bukhari.length; // β 7277
// Metadata
bukhari.metadata; // β { title, author, ... }
bukhari.chapters; // β Chapter[]{
id: 1,
chapterId: 1,
arabic: "ΨΩΨ―ΩΩΨ«ΩΩΩΨ§ Ψ§ΩΩΨΩΩ
ΩΩΩΨ―ΩΩΩΩ...",
english: {
narrator: "Umar bin Al-Khattab",
text: "I heard Allah's Messenger (ο·Ί) saying..."
}
}bukhari.find((h) => h.id === 23);
bukhari.filter((h) => h.chapterId === 1);
bukhari.map((h) => h.english.narrator);
bukhari.forEach((h) => console.log(h.id));
bukhari.slice(0, 10);Run this once inside your React project:
cd my-react-app
bukhari --reactThis auto-generates src/hooks/useBukhari.js. Then use it anywhere:
import { useBukhari } from "../hooks/useBukhari";
function HadithOfTheDay() {
const bukhari = useBukhari();
if (!bukhari) return <p>Loading...</p>;
const h = bukhari.getRandom();
return (
<div>
<p>
<strong>{h.english.narrator}</strong>
</p>
<p>{h.english.text}</p>
</div>
);
}// Search example
function HadithSearch() {
const bukhari = useBukhari();
const [results, setResults] = useState([]);
if (!bukhari) return <p>Loading...</p>;
return (
<>
<input
placeholder="Search hadiths..."
onChange={(e) => setResults(bukhari.search(e.target.value, 10))}
/>
{results.map((h) => (
<p key={h.id}>{h.english.text}</p>
))}
</>
);
}Data is fetched from jsDelivr CDN once and cached globally. All components share the same request β no duplicates.
The Python API is identical to the npm package β same camelCase method names, same behaviour.
from sahih_al_bukhari import Bukhari
bukhari = Bukhari() # reads bin/bukhari.json if in repo, else fetches from CDN
# Exact same API as JS
bukhari.get(1) # Hadith | None
bukhari.getByChapter(1) # list[Hadith]
bukhari.search("prayer") # list[Hadith]
bukhari.search("prayer", limit=5) # list[Hadith] β top 5
bukhari.getRandom() # Hadith
# Index access & iteration
bukhari[0] # first hadith
bukhari.length # 7277
len(bukhari) # 7277
for h in bukhari: print(h.id)
# Array-style methods (matches JS prototype)
bukhari.find(lambda h: h.id == 23)
bukhari.filter(lambda h: h.chapterId == 1)
bukhari.map(lambda h: h.narrator)
bukhari.slice(0, 10)
# Metadata
bukhari.metadata.english # {"title": ..., "author": ...}
bukhari.chapters # list[Chapter]# Use your own bukhari.json at any path
bukhari = Bukhari(data_path="/absolute/path/to/bukhari.json")
bukhari = Bukhari(data_path=Path(__file__).parent / "bukhari.json")from flask import Flask, jsonify, request
from sahih_al_bukhari import Bukhari
app = Flask(__name__)
bukhari = Bukhari()
@app.get("/api/hadith/random")
def random_hadith():
return jsonify(bukhari.getRandom().to_dict())
@app.get("/api/hadith/<int:hadith_id>")
def get_hadith(hadith_id):
h = bukhari.get(hadith_id)
return jsonify(h.to_dict()) if h else ("Not found", 404)
@app.get("/api/search")
def search():
return jsonify([h.to_dict() for h in bukhari.search(request.args.get("q", ""), limit=20)])The same bukhari command works whether installed via npm or pip.
# By ID
bukhari 1
bukhari 2345
# Within a chapter
bukhari 23 34
# Language flags
bukhari 2345 # English only (default)
bukhari 2345 -a # Arabic only
bukhari 2345 --arabic # Arabic only
bukhari 2345 -b # Arabic + English
bukhari 2345 --both # Arabic + English
# Search
bukhari --search "prayer"
bukhari --search "fasting" --all # show all results (default: top 5)
# Chapter listing
bukhari --chapter 5
# Random
bukhari --random
bukhari --random -b
# React hook generator (JS only β run inside your React project)
bukhari --react
# Info
bukhari --version
bukhari --helpββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Hadith #1 | Chapter: 1 β Revelation
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Narrator: Umar bin Al-Khattab
I heard Allah's Messenger (ο·Ί) saying, "The reward of deeds
depends upon the intentions and every person will get the
reward according to what he has intended..."
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
sahih-al-bukhari/
β
βββ bin/
β βββ bukhari.json β π SHARED β single source of truth for JS + Python
β βββ index.js β JS CLI entry
β
βββ chapters/ β π SHARED β generated by `node build.mjs`
β βββ meta.json used by CDN loader (JS browser) + Python CDN fallback
β βββ 1.json
β βββ ...
β
βββ sahih_al_bukhari/ β Python package
β βββ __init__.py
β βββ bukhari.py β auto-reads bin/bukhari.json
β βββ cli.py
β
βββ index.js β JS ESM (browser-safe)
βββ index.cjs β JS CommonJS
βββ index.node.js β JS Node ESM
βββ index.browser.js β JS browser / CDN (auto-generated)
βββ index.d.ts β TypeScript definitions
βββ build.mjs β generates chapters/ from bin/bukhari.json
β
βββ package.json β npm config
βββ pyproject.toml β Python / Poetry config
βββ MANIFEST.in β Python sdist: include data, exclude JS
βββ .npmignore β npm publish: exclude Python files
| File | Used by |
|---|---|
bin/bukhari.json |
JS Node (CJS + ESM) Β· Python (auto-detected from repo root) |
chapters/ |
JS browser CDN fetch Β· Python CDN fallback |
You never duplicate data. Both packages read the exact same file.
| Method | JS | Python | Returns |
|---|---|---|---|
get(id) |
β | β | Hadith | undefined/None |
getByChapter(id) |
β | β | Hadith[] |
search(query, limit?) |
β | β | Hadith[] |
getRandom() |
β | β | Hadith |
find(predicate) |
β | β | Hadith | undefined/None |
filter(predicate) |
β | β | Hadith[] |
map(fn) |
β | β | any[] |
forEach(fn) |
β | β | void/None |
slice(start, end) |
β | β | Hadith[] |
| Property | Type | Description |
|---|---|---|
length |
number / int |
Total hadiths β 7,277 |
metadata |
Metadata |
Title, author, introduction |
chapters |
Chapter[] |
All chapters |
Seed a MongoDB database (Node.js)
import { MongoClient } from "mongodb";
import bukhari from "sahih-al-bukhari";
const client = new MongoClient(process.env.MONGO_URI);
await client.connect();
await client
.db("islam")
.collection("hadiths")
.insertMany([...bukhari]);
await client.close();
console.log("Seeded", bukhari.length, "hadiths");Seed a database (Python)
from sahih_al_bukhari import Bukhari
bukhari = Bukhari()
records = [h.to_dict() for h in bukhari]
# Insert into any DB
print(f"Seeded {len(records)} hadiths")Thematic search
from sahih_al_bukhari import Bukhari
bukhari = Bukhari()
topics = ["prayer", "charity", "fasting", "knowledge", "patience"]
for topic in topics:
count = len(bukhari.search(topic))
print(f"{topic:12} β {count} hadiths")Express.js REST API
import express from "express";
import bukhari from "sahih-al-bukhari";
const app = express();
app.get("/api/hadith/random", (_, res) => res.json(bukhari.getRandom()));
app.get("/api/hadith/:id", (req, res) => {
const h = bukhari.get(parseInt(req.params.id));
h ? res.json(h) : res.status(404).json({ error: "Not found" });
});
app.get("/api/search", (req, res) =>
res.json(bukhari.search(req.query.q || "")),
);
app.get("/api/chapter/:id", (req, res) =>
res.json(bukhari.getByChapter(parseInt(req.params.id))),
);
app.listen(3000, () => console.log("Running on :3000"));git clone https://github.com/SENODROOM/sahih-al-bukhari.git
cd sahih-al-bukhari
npm install
# Regenerate chapters/ from bin/bukhari.json
node build.mjs
# Publish to npm
npm publish
# Publish to PyPI
pip install build twine
python -m build
python -m twine upload dist/*Contributions are welcome!
- Fork the repository
- Create a branch:
git checkout -b feature/my-feature - Commit:
git commit -m 'Add my feature' - Push:
git push origin feature/my-feature - Open a Pull Request
Licensed under the GNU Affero General Public License v3.0 (AGPL-3.0) β see LICENSE for details.
- π Source β Sahih al-Bukhari, the most authentic hadith collection in Islam
- π¨βπ« Translations β By reputable Islamic scholars
- π Inspiration β The global Muslim community seeking knowledge
Made with β€οΈ for the Muslim community Β· Seeking knowledge together
