Metadata-Version: 2.4
Name: FB2
Version: 0.2.1
Summary: A small package for working with FB2 files
Author-email: Ae-Mc <ae_mc@mail.ru>
License-Expression: MIT
Project-URL: Homepage, https://github.com/Ae-Mc/FB2
Project-URL: Repository, https://github.com/Ae-Mc/FB2
Project-URL: Issues, https://github.com/Ae-Mc/FB2/issues
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Operating System :: OS Independent
Classifier: Topic :: Utilities
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: iso-639==0.4.*,>=0.4.5
Dynamic: license-file

# FB2

[![PyPI](https://img.shields.io/pypi/v/fb2?color=orange)](https://pypi.org/project/fb2)

Python package for working with FictionBook2

## Usage example

```python
from urllib import request

from FB2 import Author, ChapterWithSubchapters, FictionBook2, Image, SimpleChapter

book = FictionBook2()
book.titleInfo.title = "Example book"
book.titleInfo.annotation = "Small test book. Shows basics of FB2 library"
book.titleInfo.authors = [
    Author(
        firstName="Alex",
        middleName="Unknown",
        nickname="Ae_Mc",
        emails=["ae_mc@mail.ru"],
        homePages=["ae-mc.ru"],
    )
]
book.titleInfo.genres = ["sf", "sf_fantasy", "shortstory"]
book.titleInfo.coverPageImages = [
    Image(
        media_type="image/jpeg",
        content=request.urlopen("https://picsum.photos/1080/1920").read(),
    ),
    # Multiple cover images not supported by most FB2 readers.
    # Image(
    #     media_type="image/jpeg",
    #     content=request.urlopen("https://picsum.photos/1080/1920").read(),
    # ),
]
book.titleInfo.sequences = [("Example books", 2)]
book.documentInfo.authors = ["Ae Mc"]
book.documentInfo.version = "1.1"

book.chapters = [
    SimpleChapter(
        "Introduction",
        content=[
            "Introduction chapter first paragraph",
            "Introduction chapter second paragraph",
        ],
    ),
    SimpleChapter(
        "1. Chapter one. FB2 format history",
        content=[
            "Introduction chapter first paragraph",
            "Introduction chapter second paragraph",
            Image(
                media_type="image/jpeg",
                content=request.urlopen("https://picsum.photos/1920/1080").read(),
            ),
            "Text after image 1",
            Image(
                media_type="image/jpeg",
                content=request.urlopen("https://picsum.photos/1920/1080").read(),
            ),
            "Text after image 2",
        ],
    ),
]

# Example of adding chapter with subchapters (subsections)
book.chapters.append(
    ChapterWithSubchapters(
        title="2. Chapter two. With subchapters (subsections)",
        epigraph=[
            "This is the epigraph for chapter two. It can be multiline.",
            "This is the second line of the epigraph.",
        ],
        annotation=[
            "This is the annotation for chapter two. It can also be multiline.",
            "This is the second line of the annotation.",
            "This chapter also contains cover image that goes before the text.",
        ],
        image=Image(
            media_type="image/jpeg",
            content=request.urlopen("https://picsum.photos/1920/1080").read(),
        ),
        subchapters=[
            SimpleChapter(
                title="Subchapter 2.1",
                content=[
                    "Subchapter 2.1 text",
                    "Subchapter 2.1 text 2",
                ],
            ),
            SimpleChapter(
                title="Subchapter 2.2",
                content=[
                    "Subchapter 2.2 text",
                    "Subchapter 2.2 text 2",
                ],
            ),
            ChapterWithSubchapters(
                "Subchapter 2.3",
                subchapters=[
                    SimpleChapter(
                        title="Subsubchapter 2.3.1",
                        content=[
                            "Subsubchapter 2.3.1 text",
                            "Subsubchapter 2.3.1 text 2",
                        ],
                    ),
                    SimpleChapter(
                        title="Subsubchapter 2.3.2",
                        content=[
                            "Subsubchapter 2.3.2 text",
                            "Subsubchapter 2.3.2 text 2",
                        ],
                    ),
                ],
            ),
        ],
    ),
)

book.chapters.append(SimpleChapter("3. Chapter three. Empty", []))
book.write("ExampleBook.fb2")
```

## Requirements

- iso-639 package
- Python 3.7+

## Installation

- From pip: `pip install fb2`
