Skip to main content

ozaru

Read PDF files from Python with a small, simple API and a Rust core.

PyPI version Python versions CI License: MIT

Documentation: https://jair-dev57.github.io/ozaru/

import ozaru

text = ozaru.extract_text("invoice.pdf")
pages = ozaru.page_count("invoice.pdf")
info = ozaru.metadata("invoice.pdf")

print(f"{info.title}: {pages} pages")
print(text)

Why ozaru?

  • One line per task. Pass a path and get the result. There are no objects to manage.
  • Easy to install. Prebuilt wheels mean you don't need Rust or a compiler.
  • No Python dependencies. ozaru installs nothing else into your environment.
  • Built on Rust. Every PDF is read by OZARU ENGINE, ozaru's own PDF engine, written in Rust with no other PDF library inside.
  • Typed. Type hints are included, so your editor can autocomplete and check your calls.

Installation

pip install ozaru

Or, with uv:

uv add ozaru

ozaru requires Python 3.10 or newer.

Usage

Extract text

extract_text returns the text of the whole document as a single string:

import ozaru

text = ozaru.extract_text("report.pdf")

Find words

extract_words returns every word with its page, its line and its box, in points from the top left corner of the page:

import ozaru

for word in ozaru.extract_words("report.pdf"):
    print(word.page, word.text, word.x0, word.y0, word.x1, word.y1)

Extract images

extract_images returns every image with its page, its box and its file:

import ozaru

for image in ozaru.extract_images("brochure.pdf"):
    image.save(f"page{image.page}-{image.number}.{image.format}")

Count pages

page_count returns the number of pages as an integer:

import ozaru

pages = ozaru.page_count("report.pdf")

Draw a page as an image

render_page draws a page, counted from 1, as a PNG image, with scale pixels for each point of the page:

import ozaru

png = ozaru.render_page("report.pdf", 1, scale=2)
with open("page-1.png", "wb") as file:
    file.write(png)

Read the annotations

annotations returns the links, notes, highlights and form widgets of every page, with where they are and what they say. render_page draws them unless you pass annotations=False:

import ozaru

for annotation in ozaru.annotations("report.pdf"):
    print(annotation.page, annotation.subtype, annotation.uri or annotation.contents)

Read and fill forms

form_fields lists the fields of a form with their values, and fill_form fills them and saves another file:

import ozaru

for field in ozaru.form_fields("form.pdf"):
    print(field.name, field.kind, field.value)

ozaru.fill_form("form.pdf", "filled.pdf", {"name": "Ana", "agree": True})

Protect a PDF

encrypt saves a copy protected with passwords and permissions, using AES-256:

import ozaru

ozaru.encrypt("report.pdf", "protected.pdf", user_password="1234", permissions=["print"])

Rotate pages

rotate turns pages clockwise and saves the result to another file:

import ozaru

ozaru.rotate("report.pdf", "rotated.pdf", 90)              # every page
ozaru.rotate("report.pdf", "rotated.pdf", -90, pages=[2])  # only page 2

Extract and split pages

extract_pages saves some pages, in the order given, to a new file, and split saves each page as its own file in a folder:

import ozaru

ozaru.extract_pages("report.pdf", "summary.pdf", [3, 1])
paths = ozaru.split("report.pdf", "pages")  # pages/report-1.pdf, ...

Merge PDFs

merge joins several PDFs into one file, in order:

import ozaru

ozaru.merge(["cover.pdf", "report.pdf", "annex.pdf"], "full.pdf")

Handle errors

import ozaru

try:
    text = ozaru.extract_text("report.pdf")
except FileNotFoundError:
    print("The file does not exist.")
except OSError:
    print("The file could not be read.")
except ValueError:
    print("The file could not be read as a PDF.")

Damaged pages

If a page can't be read, extract_text still returns the other pages, leaves that page empty and emits an ozaru.PageWarning with its page number:

import warnings

import ozaru

with warnings.catch_warnings(record=True) as caught:
    warnings.simplefilter("always", ozaru.PageWarning)
    text = ozaru.extract_text("report.pdf")

for warning in caught:
    print(f"Page {warning.message.page} could not be read")

API

Function Returns Raises Warns
extract_text(path) str OSError, ValueError PageWarning
extract_words(path) list[Word] OSError, ValueError PageWarning
extract_blocks(path) list[Block] OSError, ValueError PageWarning
extract_images(path) list[Image] OSError, ValueError PageWarning
page_count(path) int OSError, ValueError
metadata(path) Metadata OSError, ValueError
page_info(path) list[PageInfo] OSError, ValueError PageWarning
annotations(path) list[Annotation] OSError, ValueError PageWarning
form_fields(path) list[FormField] OSError, ValueError PageWarning
fill_form(path, output, values) None OSError, ValueError PageWarning
encrypt(path, output) None OSError, ValueError PageWarning
permissions(path) list[str] or None OSError, ValueError
render_page(path, page) bytes OSError, ValueError, IndexError PageWarning
rotate(path, output, degrees) None OSError, ValueError, IndexError PageWarning
extract_pages(path, output, pages) None OSError, ValueError, IndexError PageWarning
split(path, folder) list[Path] OSError, ValueError PageWarning
merge(paths, output) None OSError, ValueError PageWarning

Metadata has the title, author, subject, keywords, creator and producer of the PDF as str, and its creation_date and modification_date as datetime. Each one is None when the PDF doesn't have it.

Word has the page, block and line of a word, counted from 1, its text, and its box: x0, y0, x1 and y1, in points from the top left corner of the page. Block has the page, number, text and box of a paragraph or another block of text. Image has the page, number, box, width and height in pixels, format and data of an image, and save(path) writes it to a file.

PageInfo has the number, width, height and rotation of a page, with width and height in points as a viewer shows it, rotated.

Every function takes an optional password keyword argument, the user or owner password of a protected PDF. A missing or wrong password raises ozaru.PasswordError, a subclass of ValueError.

File problems raise the same OSError subclasses as Python's open(), such as FileNotFoundError, PermissionError and IsADirectoryError.

path can be a str or a pathlib.Path.

Speed

The median time of one call, in milliseconds, on a laptop with an Intel Core i5-11400H. pypdf and PyMuPDF are timed doing the same work: the text of every page, and the page count.

extract_text:

File ozaru ozaru 0.1.7 PyMuPDF 2.1 pypdf 7.0
3 pages 0.25 ms 0.64 ms 2.0 ms 3.3 ms
An invoice, 3 pages 0.95 ms 2.1 ms 2.7 ms 7.7 ms
Chinese, Japanese and Korean, 1 page 0.46 ms 2.1 ms 1.6 ms 8.5 ms
500 pages 9.5 ms 38 ms 56 ms 347 ms
1000 pages 7.1 ms 47 ms 107 ms 419 ms

page_count:

File ozaru ozaru 0.1.7 PyMuPDF 2.1 pypdf 7.0
3 pages 0.057 ms 0.080 ms 0.16 ms 0.53 ms
500 pages 1.9 ms 0.77 ms 0.30 ms 55 ms
1000 pages 1.9 ms 0.75 ms 1.8 ms 57 ms

render_page at scale 1, as PNG bytes, opening the file each time:

File ozaru PyMuPDF 2.1
An invoice, 1 page 6.9 ms 15 ms
A photo cover (1080 x 1920 pixels) 217 ms 217 ms
A smaller photo cover 16.5 ms 22 ms
A page of text of 2,380 glyphs 41 ms 41 ms

page_count reads every page of the PDF, so that damaged files are counted right, which takes longer on files with hundreds of pages. To measure on your machine, run crates/ozaru-engine/benches/compare_libraries.py.

Supported platforms

Prebuilt wheels are available for CPython 3.10 and newer:

Operating system Architectures
Linux (glibc) x86_64, aarch64
Linux (musl) x86_64, aarch64
macOS Intel, Apple Silicon
Windows x64

Before each release, the tests run against the wheels of glibc Linux, macOS and Windows on their own platform, with Python 3.10 and 3.14 (only 3.10 on Apple Silicon).

On other platforms, pip builds ozaru from source, which requires a Rust toolchain.

Limitations

ozaru is in early development, so its API may change between releases.

  • It reads the text stored in a PDF and does not perform OCR, so scanned documents may return little or no text.
  • Columns are read one after the other when the PDF paints them one after the other or row by row, but not in other orders.

Contributing

You need Rust and uv. Then run:

git clone https://github.com/Jair-dev57/ozaru.git
cd ozaru
uv run pytest

See the contributing guide. Bug reports and ideas are welcome in the issue tracker.

License

ozaru is released under the MIT License.

Metadata

Release files for ozaru 0.7.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ozaru 0.7.2
File Size Uploaded Provenance Actions
ozaru-0.7.2.tar.gz 747.7 kB Without provenance Details for ozaru-0.7.2.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for ozaru 0.7.2
File Actions
ozaru-0.7.2-cp310-abi3-win_amd64.whl CPython 3.10 abi3 Windows x86-64 Details for ozaru-0.7.2-cp310-abi3-win_amd64.whl
ozaru-0.7.2-cp310-abi3-musllinux_1_2_x86_64.whl CPython 3.10 abi3 Linux musl 1.2+ x86-64 Details for ozaru-0.7.2-cp310-abi3-musllinux_1_2_x86_64.whl
ozaru-0.7.2-cp310-abi3-musllinux_1_2_aarch64.whl CPython 3.10 abi3 Linux musl 1.2+ ARM64 Details for ozaru-0.7.2-cp310-abi3-musllinux_1_2_aarch64.whl
ozaru-0.7.2-cp310-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl CPython 3.10 abi3 Linux glibc 2.17+ x86-64 Details for ozaru-0.7.2-cp310-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
ozaru-0.7.2-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl CPython 3.10 abi3 Linux glibc 2.17+ ARM64 Details for ozaru-0.7.2-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
ozaru-0.7.2-cp310-abi3-macosx_11_0_arm64.whl CPython 3.10 abi3 macOS 11.0+ ARM64 Details for ozaru-0.7.2-cp310-abi3-macosx_11_0_arm64.whl
ozaru-0.7.2-cp310-abi3-macosx_10_12_x86_64.whl CPython 3.10 abi3 macOS 10.12+ x86-64 Details for ozaru-0.7.2-cp310-abi3-macosx_10_12_x86_64.whl

Total release size: 12.2 MB

Release files / ozaru-0.7.2.tar.gz

Download URL ozaru-0.7.2.tar.gz
Size 747.7 kB
Tags Source
SHA-256 checksum
How to use checksums
6e23589a73491d011f0dddeeb57ad53ebd2ae86e360c90e6aaf9753b580ae2f8
BLAKE2b-256 checksum
How to use checksums
5ee59aff34acac4c95296dde6057e5de1532288b5d40d5e1cdfe28597b7857aa
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.9 {"installer":{"name":"uv","version":"0.13.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / ozaru-0.7.2-cp310-abi3-win_amd64.whl

Download URL ozaru-0.7.2-cp310-abi3-win_amd64.whl
Size 1.5 MB
Tags CPython 3.10 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
1d2af2456f1a243d6180dbfd4e67254c5ae224ea9dafa82d94a11ebe9b547495
BLAKE2b-256 checksum
How to use checksums
fc1b65ee9f54b3d3f12727102d519f473581e457465454e23336e887bcfa5c13
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.9 {"installer":{"name":"uv","version":"0.13.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / ozaru-0.7.2-cp310-abi3-musllinux_1_2_x86_64.whl

Download URL ozaru-0.7.2-cp310-abi3-musllinux_1_2_x86_64.whl
Size 1.9 MB
Tags CPython 3.10 Linux musl 1.2+ x86-64 abi3
SHA-256 checksum
How to use checksums
7e4d6b945a1ee447a51f1ce00abdb6c4ef618185dbcc544cce6210e99b362a8b
BLAKE2b-256 checksum
How to use checksums
36440c18dd5ce9858c4b68fa89d8bc15e98bb8f960268b3ee0fb034e6eb62779
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.9 {"installer":{"name":"uv","version":"0.13.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / ozaru-0.7.2-cp310-abi3-musllinux_1_2_aarch64.whl

Download URL ozaru-0.7.2-cp310-abi3-musllinux_1_2_aarch64.whl
Size 1.8 MB
Tags CPython 3.10 Linux musl 1.2+ ARM64 abi3
SHA-256 checksum
How to use checksums
b8f6d2e0de96946daaef3165e60e0eb38fc4cd469738d2c871777733317ad4ea
BLAKE2b-256 checksum
How to use checksums
78585ef9ae56edadf06ac06fcabe7d5c828de30c5fb00ffadee9cfc976962e0f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.9 {"installer":{"name":"uv","version":"0.13.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / ozaru-0.7.2-cp310-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl

Download URL ozaru-0.7.2-cp310-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Size 1.6 MB
Tags CPython 3.10 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
05c23dd99b5cb306034c5f815e63f5e746da436a6a98ba2d3605e5a857c51cb7
BLAKE2b-256 checksum
How to use checksums
350badc6d4c4bca5e5ce7de684f9ddda8edf2f538397157246e3fe18b228388d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.9 {"installer":{"name":"uv","version":"0.13.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / ozaru-0.7.2-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl

Download URL ozaru-0.7.2-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
Size 1.6 MB
Tags CPython 3.10 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
25dfd818748294e0349170a7d4010122464a8c6411e4b8f90bf9b5c84f707084
BLAKE2b-256 checksum
How to use checksums
139241288651369760b8dcf7244e53fa8d75315a04d5d6efca89138c3eef2eb2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.9 {"installer":{"name":"uv","version":"0.13.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / ozaru-0.7.2-cp310-abi3-macosx_11_0_arm64.whl

Download URL ozaru-0.7.2-cp310-abi3-macosx_11_0_arm64.whl
Size 1.5 MB
Tags CPython 3.10 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
427e942dc7853329c497b16065bed2ddbfc3920e736151c197be05119adafd3c
BLAKE2b-256 checksum
How to use checksums
2cc3517f0fdc0da01c61fa2a84f8fec2e421ac1a5fe8463697e9bf7bf6859005
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.9 {"installer":{"name":"uv","version":"0.13.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / ozaru-0.7.2-cp310-abi3-macosx_10_12_x86_64.whl

Download URL ozaru-0.7.2-cp310-abi3-macosx_10_12_x86_64.whl
Size 1.6 MB
Tags CPython 3.10 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
85a48b7274cdd37e20d4ba47a8b9481f7b4403eef9852823478fc5454e8cf71d
BLAKE2b-256 checksum
How to use checksums
ab55ae9a0c02c0b17115fb6fb51ae126d54268d604f5df0fe7fb0b6cf63b1bd1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.9 {"installer":{"name":"uv","version":"0.13.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for ozaru 0.7.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.7.2 This release

8 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page