A lightweight and elegant Python library for RanobeLib API
- π Simple and intuitive API -
Search("query")just works - π Complete chapter and volume management
- π Powerful catalog search with pagination
- π‘οΈ Error handling with custom exceptions
- π Full type hints support
- π― Minimal dependencies (only requests)
- π Python 3.7+ support
pip install requestsClone and install:
git clone https://github.com/AugustLigh/RanobeLibLight
cd ranobelib
pip install -e .from ranobeliblight import Search
# Simple search - one line!
results = Search("daughter of evil")
# Iterate over results
for manga in results[:5]:
print(f"{manga.rus_name} - {manga.rating.averageFormated}β
")
print(f" Status: {manga.status.label}")
print(f" URL: {manga.url}\n")from ranobeliblight import Ranobe
# Create ranobe object (use slug from URL)
ranobe = Ranobe('41368--nemurase-hime-kara-no-gifuto')
# Get info
print(f"Title: {ranobe.title}")
# Get chapters
chapters = ranobe.get_chapters()
print(f"Total chapters: {len(chapters)}")
# Filter chapters
chapters_vol_1 = chapters.filter_by_volume('1')
chapters_range = chapters.filter_by_number_range(1, 10)
# Get chapter content
chapter = chapters[0]
content = ranobe.get_chapter_content(chapter.number, chapter.volume)
text = content.get_text()
print(f"\n{chapter.name}")
print(f"Words: {content.word_count}, Characters: {content.char_count}")
print(f"\n{text[:500]}...")from ranobeliblight import Ranobe
ranobe = Ranobe('41368--nemurase-hime-kara-no-gifuto')
# Get chapters
chapters = ranobe.get_chapters()
filtered = chapters.filter_by_number_range(1, 10)
# Save to text file
with open('chapters.txt', 'w', encoding='utf-8') as f:
for chapter in filtered:
content = ranobe.get_chapter_content(chapter.number, chapter.volume)
f.write(f"\n{'='*60}\n")
f.write(f"{chapter.name}\n")
f.write(f"Volume {chapter.volume}, Chapter {chapter.number}\n")
f.write(f"{'='*60}\n\n")
f.write(content.get_text())
f.write("\n\n")Quick search function - the simplest way to search!
from ranobeliblight import Search
# Simple search
results = Search("magic")
# With pagination
page_2 = Search("magic", page=2, per_page=10)Returns: SearchResponse object
Advanced search with more control.
from ranobeliblight import Search
# Create searcher
searcher = Search("magic")
# Get all pages
all_pages = searcher.all_pages("magic", max_pages=3)| Method | Description | Returns |
|---|---|---|
__call__(query, page=1, per_page=20) |
Search by query | SearchResponse |
all_pages(query, max_pages=None) |
Search all pages | List[SearchResponse] |
Main class for working with ranobe.
from ranobeliblight import Ranobe
ranobe = Ranobe('your-slug-here')| Method | Description | Returns |
|---|---|---|
get_info(fields=None) |
Get ranobe information | dict |
get_chapters() |
Get all chapters | ChaptersList |
get_chapter_content(number, volume) |
Get chapter content | ChapterContent |
get_chapter_text(number, volume) |
Get chapter text | str |
get_chapter_by_index(index) |
Get chapter by index | Chapter |
| Property | Description |
|---|---|
title |
Russian title |
url |
Full URL on website |
Chapters list with convenient filtering methods.
| Method | Description |
|---|---|
filter_by_volume(volume) |
Filter by volume |
filter_by_number_range(min, max) |
Filter by number range |
get_by_number(number, volume=None) |
Get chapter by number |
filter(predicate) |
Filter by custom condition |
get_volumes() |
Get list of volumes |
group_by_volume() |
Group chapters by volume |
Examples:
chapters = ranobe.get_chapters()
# Filtering
vol_2 = chapters.filter_by_volume('2')
first_10 = chapters.filter_by_number_range(1, 10)
custom = chapters.filter(lambda ch: float(ch.volume) > 1)
# Grouping
by_volume = chapters.group_by_volume()
for vol, chs in by_volume.items():
print(f"Volume {vol}: {len(chs)} chapters")Chapter content.
| Method | Description |
|---|---|
get_text(separator="\n") |
Get all text |
get_paragraphs() |
Get list of paragraphs |
| Property | Description |
|---|---|
word_count |
Word count |
char_count |
Character count |
The library provides specialized exceptions:
from ranobeliblight import (
RanobeLibException, # Base exception
RanobeNotFoundError, # Ranobe not found
ChapterNotFoundError, # Chapter not found
APIError, # API error
NetworkError, # Network error
InvalidParameterError # Invalid parameter
)
try:
ranobe = Ranobe('invalid-id')
info = ranobe.get_info()
except RanobeNotFoundError as e:
print(f"Ranobe not found: {e}")
except NetworkError as e:
print(f"Network problem: {e}")from ranobeliblight import Ranobe, RanobeSession
# Create session with custom timeout
session = RanobeSession(timeout=60)
ranobe = Ranobe('your-slug', session=session)from ranobeliblight import Search
# Paginated search using function
page_1 = Search("magic", page=1, per_page=10)
page_2 = Search("magic", page=2, per_page=10)
# Or get all pages at once using class
searcher = Search()
all_pages = searcher.all_pages("magic", max_pages=3)
all_results = [result for page in all_pages for result in page]from ranobeliblight import Ranobe
import time
ranobe = Ranobe('your-slug')
chapters = ranobe.get_chapters()
for i, chapter in enumerate(chapters, 1):
try:
content = ranobe.get_chapter_content(chapter.number, chapter.volume)
# Save
filename = f"chapter_{chapter.number}.txt"
with open(filename, 'w', encoding='utf-8') as f:
f.write(content.get_text())
print(f"[{i}/{len(chapters)}] β {chapter.name}")
# Small delay to avoid overloading API
time.sleep(0.5)
except Exception as e:
print(f"[{i}/{len(chapters)}] β Error: {e}")from ranobeliblight import Ranobe
def escape_rtf(text):
"""Escape special characters for RTF"""
result = ""
for char in text:
code = ord(char)
if code < 128:
if char == '\\':
result += '\\\\'
elif char == '{':
result += '\\{'
elif char == '}':
result += '\\}'
elif char == '\n':
result += '\\par\n'
else:
result += char
else:
result += f'\\u{code}?'
return result
# Create RTF document
ranobe = Ranobe('41368--nemurase-hime-kara-no-gifuto')
chapters = ranobe.get_chapters()
rtf_content = r"""{\rtf1\ansi\ansicpg1251\deff0
{\fonttbl{\f0\fnil\fcharset204 Times New Roman;}}
\viewkind4\uc1\pard\lang1049\f0\fs24
"""
for chapter in chapters[:10]: # First 10 chapters
content = ranobe.get_chapter_content(chapter.number, chapter.volume)
# Add title
rtf_content += r"\b\fs28 " + escape_rtf(chapter.name) + r"\b0\fs24\par\par" + "\n"
# Add text
rtf_content += escape_rtf(content.get_text()) + "\n\\page\n"
rtf_content += "}"
# Save
with open('output.rtf', 'w', encoding='ascii') as f:
f.write(rtf_content)ranobeliblight/
βββ __init__.py # Main module with exports
βββ ranobe.py # Ranobe class
βββ search.py # Search class and function
βββ constant.py # Session and constants
βββ exceptions.py # Exceptions
βββ models/ # Data models
βββ __init__.py
βββ chapters.py # Chapter models
βββ chapter_content.py # Content models
βββ search.py # Search models
- Use chapter filtering for working with large ranobe
- Add delays when bulk downloading (use
time.sleep()) - Handle exceptions for reliable operation
- Cache results if making many requests
- Use
get_chapter_text()if you only need text without metadata
More examples in the project folder:
example.py- Export to RTFexample_search.py- Search examplesexample_usage.py- Get ranobe informationsearch_download.py- Search and download in one file
- API may have rate limiting - add delays between requests
- Some ranobe may be unavailable or require authentication
- Content format may vary depending on source
MIT License - use freely!
Thanks to RanobeLib for the API and all ranobe readers! πβ¨
Made with β€οΈ for ranobe lovers