Skip to main content

Unofficial Python SDK for the Sefaria API

Project description

Unofficial Sefaria Python SDK

Python 3.8+ License: MIT

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-wrapper endpoint with advanced query capabilities
  • Texts: v3 API with comprehensive parameter support and language options
  • Related Content: /related/{tref} endpoint for content relationships
  • Languages: /texts/translations for 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 support
  • search(query, **kwargs) - Advanced search with highlighting
  • get_related(tref) - Find related texts and commentaries
  • get_languages() - Available translation languages
  • get_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

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sefaria_sdk-0.1.1.tar.gz (16.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sefaria_sdk-0.1.1-py3-none-any.whl (18.0 kB view details)

Uploaded Python 3

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

Hashes for sefaria_sdk-0.1.1.tar.gz
Algorithm Hash digest
SHA256 82a625da9041eff6e025666cfa47e6a41b23b8f338220bae7a603531a32a08fa
MD5 8f7024573450df0a08c56d6ddcbe2e88
BLAKE2b-256 45d8092e37c519f134f5e3da1f67bb30f3ce2d08626558a7bd5651ddf60985df

See more details on using hashes here.

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

Hashes for sefaria_sdk-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 8d7b05e9293b0ac96f0c872ca8b4c2625cf35c35e84be529860ceb989808aab1
MD5 64d6b60eb714158baa855b1f63de2b62
BLAKE2b-256 b1b324486de807e4095a8ff29a40fe6bc811f7749d6fb0b94831d06e25817dfd

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page