Unofficial Python SDK for the Sefaria API
Project description
Unofficial Sefaria Python SDK
A comprehensive, modernized Python SDK for interacting with the Sefaria API, featuring robust client architecture, extensive examples, and full compatibility with current API endpoints.
โจ Features
๐ Modern API Support
- Search: POST
/search-wrapperendpoint with advanced query capabilities - Texts: v3 API with comprehensive parameter support and language options
- Related Content:
/related/{tref}endpoint for content relationships - Languages:
/texts/translationsfor available translations discovery
๐ช Robust Client Architecture
- Connection pooling with
requests.Session() - Exponential backoff retry strategy for reliability
- Configurable timeouts and headers
- Comprehensive error handling and logging
โก Async Support
- High-performance async client for bulk operations
- Concurrent text fetching capabilities
- Proper session management and resource cleanup
๐ Data Export Tools
- JSON: Full text structure preservation
- CSV: Verse-by-verse data export
- PDF: Clean English text generation
- HTML: Tag removal and formatting
๐ ๏ธ Installation
# Clone the repository
git clone https://github.com/rbrtjns90/unofficial_sefaria_python_sdk.git
cd unofficial_sefaria_python_sdk
# Install the SDK
pip install -e .
# Install example dependencies
pip install -r requirements.txt
๐ Quick Start
from sefaria_sdk import SefariaClient
# Initialize client
client = SefariaClient()
# Search for texts
results = client.search("charity", limit=5)
print(f"Found {results['hits']['total']} results")
# Get text with specific version
text = client.get_text("Genesis 1:1", lang="en")
print(text['versions'][0]['text'])
# Get related content
related = client.get_related("Genesis 1:1")
print(f"Found {len(related['links'])} related texts")
# Get available languages
languages = client.get_languages()
print(f"Available languages: {list(languages.keys())}")
๐ Examples
All examples are tested and working with the current Sefaria API:
Command Line Interface
# Search for texts
python examples/04_cli/sefaria_cli.py search "charity" -n 5
# Get specific text
python examples/04_cli/sefaria_cli.py get-text "Psalms 23:1"
# View today's calendar
python examples/04_cli/sefaria_cli.py today
Web Application
# Run Flask Torah portion viewer
python examples/02_web_app/flask_torah_app.py
# Visit http://localhost:5000
Async Text Processing
# Fetch multiple texts concurrently
python examples/05_async/async_text_fetcher_fixed.py
Data Export
# Export texts to multiple formats
python examples/06_data_export/text_exporter.py
# Generates JSON, CSV, and PDF files
๐ง API Methods
Core Methods
get_text(tref, **kwargs)- Retrieve text with full v3 API supportsearch(query, **kwargs)- Advanced search with highlightingget_related(tref)- Find related texts and commentariesget_languages()- Available translation languagesget_calendar()- Jewish calendar information
Advanced Features
- Automatic retry with exponential backoff
- Session-based connection pooling
- Configurable timeouts and headers
- Comprehensive error handling
๐ Project Structure
unofficial_sefaria_python_sdk/
โโโ sefaria_sdk/
โ โโโ client.py # Main SDK client
โ โโโ text_processing.py # Text utilities
โ โโโ __init__.py
โโโ examples/
โ โโโ 01_basic_usage/ # Basic API usage
โ โโโ 02_web_app/ # Flask web application
โ โโโ 03_research/ # Text analysis tools
โ โโโ 04_cli/ # Command line interface
โ โโโ 05_async/ # Async text fetching
โ โโโ 06_data_export/ # Multi-format export
โ โโโ 06_improved_api/ # Modern API showcase
โโโ requirements.txt
โโโ setup.py
โโโ README.md
๐ Recent Updates
API Compatibility (August 2024)
- โ
Updated search to use POST
/search-wrapper - โ Fixed text retrieval for current API response structure
- โ Corrected language parameter handling
- โ Enhanced error handling and retries
Example Fixes
- โ CLI Search: Now displays actual results instead of "N/A"
- โ Async Fetcher: Retrieves real English text content
- โ Text Exporter: Proper API response parsing for all formats
- โ Modern Demo: Working search and related content features
๐ค Contributing
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
Development Setup
# Install development dependencies
pip install -r requirements.txt
# Run tests
python -m pytest
# Format code
black sefaria_sdk/ examples/
๐ License
This project is licensed under the MIT License - see the LICENSE file for details.
โ ๏ธ Disclaimer
This is an unofficial SDK and is not affiliated with or endorsed by Sefaria. Please respect Sefaria's API usage guidelines and terms of service.
๐ Links
Made with โค๏ธ for the Jewish learning community
Project details
Release history Release notifications | RSS feed
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 sefaria_sdk-0.1.1.tar.gz.
File metadata
- Download URL: sefaria_sdk-0.1.1.tar.gz
- Upload date:
- Size: 16.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
82a625da9041eff6e025666cfa47e6a41b23b8f338220bae7a603531a32a08fa
|
|
| MD5 |
8f7024573450df0a08c56d6ddcbe2e88
|
|
| BLAKE2b-256 |
45d8092e37c519f134f5e3da1f67bb30f3ce2d08626558a7bd5651ddf60985df
|
File details
Details for the file sefaria_sdk-0.1.1-py3-none-any.whl.
File metadata
- Download URL: sefaria_sdk-0.1.1-py3-none-any.whl
- Upload date:
- Size: 18.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8d7b05e9293b0ac96f0c872ca8b4c2625cf35c35e84be529860ceb989808aab1
|
|
| MD5 |
64d6b60eb714158baa855b1f63de2b62
|
|
| BLAKE2b-256 |
b1b324486de807e4095a8ff29a40fe6bc811f7749d6fb0b94831d06e25817dfd
|