A comprehensive, modernized Python SDK for interacting with the Sefaria API, featuring robust client architecture, extensive examples, and full compatibility with current API endpoints.
- 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
- Connection pooling with
requests.Session() - Exponential backoff retry strategy for reliability
- Configurable timeouts and headers
- Comprehensive error handling and logging
- High-performance async client for bulk operations
- Concurrent text fetching capabilities
- Proper session management and resource cleanup
- JSON: Full text structure preservation
- CSV: Verse-by-verse data export
- PDF: Clean English text generation
- HTML: Tag removal and formatting
# 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.txtfrom 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())}")All examples are tested and working with the current Sefaria API:
# 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# Run Flask Torah portion viewer
python examples/02_web_app/flask_torah_app.py
# Visit http://localhost:5000# Fetch multiple texts concurrently
python examples/05_async/async_text_fetcher_fixed.py# Export texts to multiple formats
python examples/06_data_export/text_exporter.py
# Generates JSON, CSV, and PDF filesget_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
- Automatic retry with exponential backoff
- Session-based connection pooling
- Configurable timeouts and headers
- Comprehensive error handling
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
- ✅ Updated search to use POST
/search-wrapper - ✅ Fixed text retrieval for current API response structure
- ✅ Corrected language parameter handling
- ✅ Enhanced error handling and retries
- ✅ 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
- 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
# Install development dependencies
pip install -r requirements.txt
# Run tests
python -m pytest
# Format code
black sefaria_sdk/ examples/This project is licensed under the MIT License - see the LICENSE file for details.
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.
Made with ❤️ for the Jewish learning community