class sycamore.functions.DrawBoxes(font_path: str, default_color: str = 'blue')[source]#

DrawBoxes is a class for adding/drawing boxes around elements within images represented as Document objects.

This class is designed to enhance Document objects representing images with elements (e.g., text boxes, tables) by drawing bounding boxes around each element. It also allows you to customize the color mapping for different element types.

  • font_path – The path to the TrueType font file to be used for labeling.

  • default_color – The default color for bounding boxes when the element type is unknown.


context = sycamore.init()


pdf_docset =, binary_format="pdf")
    .map_batch(DrawBoxes, f_constructor_args=[font_path])
class sycamore.functions.TextOverlapChunker(chunk_token_count: int = 1000, chunk_overlap_token_count: int = 100)[source]#

TextOverlapChunker is a class for chunking text into smaller segments while allowing for token overlap.

This class inherits from the Chunker class and is designed to divide long text tokens into chunks, each containing a specified number of tokens. It allows for a controlled overlap of tokens between adjacent chunks.

  • chunk_token_count – The maximum number of tokens to include in each chunk.

  • chunk_overlap_token_count – The number of tokens that can overlap between adjacent chunks. This value must be less than the chunk_token_count to ensure meaningful chunking.


chunker = TextOverlapChunker(chunk_token_count=1000, chunk_overlap_token_count=100)
chunks = chunker.chunk(data)
sycamore.functions.filter_elements(document: Document, filter_function: Callable[[Element], bool]) list[Element][source]#

Filters the elements.

  • document – Document for which the elements need to be filtered

  • filter_function – A filter function


List of filtered elements

sycamore.functions.reorder_elements(document: Document, comparator: Callable[[Element, Element], int]) Document[source]#

Reorders the elements.

  • document – Document for which the elements need to be re-ordered

  • comparator – A comparator function


Document with elements re-ordered

sycamore.functions.split_and_convert_to_image(doc: Document) list[Document][source]#

Split a document into individual pages as images and convert them into Document objects.

This function takes a Document object, which may represent a multi-page document, and splits it into individual pages. Each page is converted into an image, and a new Document object is created for each page. The resulting list contains these new Document objects, each representing one page of the original document and elements making up the page.

The input Document object should have a binary_representation attribute containing the binary data of the pdf document. Each page’s elements are preserved in the new Document objects, and page-specific properties are updated to reflect the image’s size, mode, and page number.


doc – The input Document to split and convert.


A list of Document objects, each representing a single page of the original document as an image and elements making up the page.


input_doc = Document(binary_representation=pdf_bytes, elements=elements, properties={"author": "John Doe"})
page_docs = split_and_convert_to_image(input_doc)