The complete Sahih Muslim β 7,563 hadiths, full Arabic & English.
One repo Β· one dataset Β· published on both npm and PyPI.
| Feature | Details | |
|---|---|---|
| π | Complete Collection | All 7,563 authentic hadiths from Sahih Muslim |
| π | Bilingual | Full Arabic text + English translation for every hadith |
| π | Chapters | 2,200+ 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 useMuslim() 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/muslim.json shared by both JS and Python |
| JavaScript / Node.js | Python |
# local (for projects)
npm install sahih-muslim
# global (for CLI)
npm install -g sahih-muslim |
# local (for projects)
pip install sahih-muslim
# global CLI is included automatically |
// CommonJS β require()
const muslim = require("sahih-muslim");
// ESM β import
import muslim from "sahih-muslim";
// Get by ID
muslim.get(1); // β Hadith
// Get by chapter
muslim.getByChapter(1); // β Hadith[]
// Full-text search
muslim.search("prayer"); // β Hadith[]
// Random
muslim.getRandom(); // β Hadith
// Index access
muslim[0]; // β Hadith (first)
muslim.length; // β 7563
// Metadata
muslim.metadata; // β { title, author, ... }
muslim.chapters; // β Chapter[]{
id: 1,
chapterId: 1,
arabic: "ΨΩΨ―ΩΩΨ«ΩΩΩΩ ΩΩΨΩΩΩΩ Ψ¨ΩΩΩ ΩΩΨΩΩΩΩ...",
english: {
narrator: "Yahya bin Yahya",
text: "It is narrated on the authority of Amir al-Mu'minin..."
}
}muslim.find((h) => h.id === 23);
muslim.filter((h) => h.chapterId === 1);
muslim.map((h) => h.english.narrator);
muslim.forEach((h) => console.log(h.id));
muslim.slice(0, 10);Run this once inside your React project:
cd my-react-app
muslim --reactThis auto-generates src/hooks/useMuslim.js. Then use it anywhere:
import { useMuslim } from "../hooks/useMuslim";
function HadithOfTheDay() {
const muslim = useMuslim();
if (!muslim) return <p>Loading...</p>;
const h = muslim.getRandom();
return (
<div>
<p>
<strong>{h.english.narrator}</strong>
</p>
<p>{h.english.text}</p>
</div>
);
}// Search example
function HadithSearch() {
const muslim = useMuslim();
const [results, setResults] = useState([]);
if (!muslim) return <p>Loading...</p>;
return (
<>
<input
placeholder="Search hadiths..."
onChange={(e) => setResults(muslim.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_muslim import Muslim
muslim = Muslim() # reads bin/muslim.json if in repo, else fetches from CDN
# Exact same API as JS
muslim.get(1) # Hadith | None
muslim.getByChapter(1) # list[Hadith]
muslim.search("prayer") # list[Hadith]
muslim.search("prayer", limit=5) # list[Hadith] β top 5
muslim.getRandom() # Hadith
# Index access & iteration
muslim[0] # first hadith
muslim.length # 7563
len(muslim) # 7563
for h in muslim: print(h.id)
# Array-style methods (matches JS prototype)
muslim.find(lambda h: h.id == 23)
muslim.filter(lambda h: h.chapterId == 1)
muslim.map(lambda h: h.narrator)
muslim.slice(0, 10)
# Metadata
muslim.metadata.english # {"title": ..., "author": ...}
muslim.chapters # list[Chapter]# Use your own muslim.json at any path
muslim = Muslim(data_path="/absolute/path/to/muslim.json")
muslim = Muslim(data_path=Path(__file__).parent / "muslim.json")from flask import Flask, jsonify, request
from sahih_muslim import Muslim
app = Flask(__name__)
muslim = Muslim()
@app.get("/api/hadith/<int:hadith_id>")
def get_hadith(hadith_id):
h = muslim.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 muslim.search(request.args.get("q", ""), limit=20)])The same muslim command works whether installed via npm or pip.
# By ID
muslim 1
muslim 2345
# Within a chapter
muslim 23 34
# Language flags
muslim 2345 # English only (default)
muslim 2345 -a # Arabic only
muslim 2345 --arabic # Arabic only
muslim 2345 -b # Arabic + English
muslim 2345 --both # Arabic + English
# Search
muslim --search "prayer"
muslim --search "fasting" --all # show all results (default: top 5)
# Chapter listing
muslim --chapter 5
# Random
muslim --random
muslim --random -b
# React hook generator (JS only β run inside your React project)
muslim --react
# Info
muslim --version
muslim --helpββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Hadith #1 | Chapter: 1 β Faith
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Narrator: Yahya bin Yahya
It is narrated on the authority of Amir al-Mu'minin, Abu Hafs
Umar ibn al-Khattab, who said: I heard the Messenger of Allah
(ο·Ί) say: "Actions are judged by intentions..."
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
sahih-muslim/
β
βββ bin/
β βββ muslim.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_muslim/ β Python package
β βββ __init__.py
β βββ muslim.py β auto-reads bin/muslim.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/muslim.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/muslim.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,563 |
metadata |
Metadata |
Title, author, introduction |
chapters |
Chapter[] |
All chapters |
Seed a MongoDB database (Node.js)
import { MongoClient } from "mongodb";
import muslim from "sahih-muslim";
const client = new MongoClient(process.env.MONGO_URI);
await client.connect();
await client
.db("islam")
.collection("hadiths")
.insertMany([...muslim]);
await client.close();
console.log("Seeded", muslim.length, "hadiths");Seed a database (Python)
from sahih_muslim import Muslim
muslim = Muslim()
records = [h.to_dict() for h in muslim]
# Insert into any DB
print(f"Seeded {len(records)} hadiths")Thematic search
from sahih_muslim import Muslim
muslim = Muslim()
topics = ["prayer", "charity", "fasting", "knowledge", "patience"]
for topic in topics:
count = len(muslim.search(topic))
print(f"{topic:12} β {count} hadiths")Express.js REST API
import express from "express";
import muslim from "sahih-muslim";
const app = express();
app.get("/api/hadith/random", (_, res) => res.json(muslim.getRandom()));
app.get("/api/hadith/:id", (req, res) => {
const h = muslim.get(parseInt(req.params.id));
h ? res.json(h) : res.status(404).json({ error: "Not found" });
});
app.get("/api/search", (req, res) =>
res.json(muslim.search(req.query.q || "")),
);
app.get("/api/chapter/:id", (req, res) =>
res.json(muslim.getByChapter(parseInt(req.params.id))),
);
app.listen(3000, () => console.log("Running on :3000"));git clone https://github.com/SENODROOM/sahih-muslim.git
cd sahih-muslim
npm install
# Regenerate chapters/ from bin/muslim.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 Muslim, one of the most authentic hadith collections in Islam
- π¨βπ« Translations β By reputable Islamic scholars
- π Inspiration β The global Muslim community seeking knowledge
Made with β€οΈ for the Muslim community Β· Seeking knowledge together
