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)

Count pages

page_count returns the number of pages as an integer:

import ozaru

pages = ozaru.page_count("report.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
page_count(path) int OSError, ValueError
metadata(path) Metadata OSError, ValueError
page_info(path) list[PageInfo] 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.

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

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.3.3

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.3.3
File Size Uploaded Provenance Actions
ozaru-0.3.3.tar.gz 276.7 kB Without provenance Details for ozaru-0.3.3.tar.gz

Built distributions (wheels)

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

Total release size: 6.0 MB

Release files / ozaru-0.3.3.tar.gz

Download URL ozaru-0.3.3.tar.gz
Size 276.7 kB
Tags Source
SHA-256 checksum
How to use checksums
579ea99f4dcf5e2bda3f8e02138e9f7382a8b561ad1020890b68bffe53971a46
BLAKE2b-256 checksum
How to use checksums
dfd908cff669f2e40a6198c89678a54b33fa9db99caf63061d60fd5dea31d6ff
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.7 {"installer":{"name":"uv","version":"0.13.7","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.3.3-cp310-abi3-win_amd64.whl

Download URL ozaru-0.3.3-cp310-abi3-win_amd64.whl
Size 638.8 kB
Tags CPython 3.10 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
d0b767a218819205c34612d63f41a5223be54e2c71ed3b83238080a0f5ddb365
BLAKE2b-256 checksum
How to use checksums
bb62ec283514825bb25c088b4b81d6491967874d2fa99b027c59a9498f1e90fd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.7 {"installer":{"name":"uv","version":"0.13.7","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.3.3-cp310-abi3-musllinux_1_2_x86_64.whl

Download URL ozaru-0.3.3-cp310-abi3-musllinux_1_2_x86_64.whl
Size 1.0 MB
Tags CPython 3.10 Linux musl 1.2+ x86-64 abi3
SHA-256 checksum
How to use checksums
cda2a957c2b01cfe6086e3c3988d779aa0c715efff9ef746abc0b1249b4689e2
BLAKE2b-256 checksum
How to use checksums
5b5c892928e09c65045e94031570d55f3d15c13e612a72aa69940f9d4fac1f62
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.7 {"installer":{"name":"uv","version":"0.13.7","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.3.3-cp310-abi3-musllinux_1_2_aarch64.whl

Download URL ozaru-0.3.3-cp310-abi3-musllinux_1_2_aarch64.whl
Size 970.3 kB
Tags CPython 3.10 Linux musl 1.2+ ARM64 abi3
SHA-256 checksum
How to use checksums
c8f00432cac221828a21add565de5e9a7446d1cc3074b2040906a2e1ff887595
BLAKE2b-256 checksum
How to use checksums
42589305f3bb921ad959745e860b879dada56323f5b9c580d7eb6350e37fa700
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.7 {"installer":{"name":"uv","version":"0.13.7","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.3.3-cp310-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl

Download URL ozaru-0.3.3-cp310-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Size 814.6 kB
Tags CPython 3.10 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
04fe5173470ccaf4a04a4a76fea78f7f3b59dac8452363174e8133ab5774bd64
BLAKE2b-256 checksum
How to use checksums
62dac1a059f7df701fbe0ae7dd9362480e0f190693c13a561a1bc15656edf592
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.7 {"installer":{"name":"uv","version":"0.13.7","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.3.3-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl

Download URL ozaru-0.3.3-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
Size 792.2 kB
Tags CPython 3.10 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
192737c1bbc46bd2b9f06ef8d3e182dcfbe31a25400fb06681c1c8304c04777e
BLAKE2b-256 checksum
How to use checksums
14fc4b6379c9a74d4213ca155a912a6f7d4c8151cc9f80956598113797a3f4f0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.7 {"installer":{"name":"uv","version":"0.13.7","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.3.3-cp310-abi3-macosx_11_0_arm64.whl

Download URL ozaru-0.3.3-cp310-abi3-macosx_11_0_arm64.whl
Size 701.3 kB
Tags CPython 3.10 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
825a9ac2beb98e1dbe03fe1957d833543fb9564a0fdbfa10ce9ef8f797bac876
BLAKE2b-256 checksum
How to use checksums
1edd7288d780f39cd1983d0be654ae7933cc8530a569c4f5e8942a530db6f537
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.7 {"installer":{"name":"uv","version":"0.13.7","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.3.3-cp310-abi3-macosx_10_12_x86_64.whl

Download URL ozaru-0.3.3-cp310-abi3-macosx_10_12_x86_64.whl
Size 748.5 kB
Tags CPython 3.10 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
dc9384ea87d0f4952bf7a6b993638c7de2cc87364a91c79d6ad840ea8ba52c37
BLAKE2b-256 checksum
How to use checksums
b4be8fc75c185ab0e61fc3f8c71984b93dc44e630f0dc4b2fd352c8661d61dda
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.7 {"installer":{"name":"uv","version":"0.13.7","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.3.3

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.3.3 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