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")

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

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.
  • Text comes in the order the PDF paints it, so pages with several columns, or written right to left as in Arabic and Hebrew, may not come in reading order.

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

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.1
File Size Uploaded Provenance Actions
ozaru-0.3.1.tar.gz 261.3 kB Without provenance Details for ozaru-0.3.1.tar.gz

Built distributions (wheels)

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

Total release size: 5.5 MB

Release files / ozaru-0.3.1.tar.gz

Download URL ozaru-0.3.1.tar.gz
Size 261.3 kB
Tags Source
SHA-256 checksum
How to use checksums
362a3444148bf4dc44920d30a6124ec17e92b55ff6e94e670c0aff2c640d14dd
BLAKE2b-256 checksum
How to use checksums
75d575efaa572b46f5dd47051d59b773c804aedff5dba26bff5ab6cfc59893ac
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":"24.04","id":"noble","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.1-cp310-abi3-win_amd64.whl

Download URL ozaru-0.3.1-cp310-abi3-win_amd64.whl
Size 567.1 kB
Tags CPython 3.10 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
9ee1773859ff1e041c4df321a1a531f4d78e79a80b9149a5f2b2511c870caa81
BLAKE2b-256 checksum
How to use checksums
17c0d4263e02583333b79323de62db28da29164601cb651b89e3636c90a56613
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":"24.04","id":"noble","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.1-cp310-abi3-musllinux_1_2_x86_64.whl

Download URL ozaru-0.3.1-cp310-abi3-musllinux_1_2_x86_64.whl
Size 955.9 kB
Tags CPython 3.10 Linux musl 1.2+ x86-64 abi3
SHA-256 checksum
How to use checksums
b508d5ff91caade3adcd1c85d4c22c2d608d21f6bba3ce510695e4540a9d4bf2
BLAKE2b-256 checksum
How to use checksums
05bec69b384c36766b4f51852d722a2ec473c0bb7872fd6102d47e2914905a4f
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":"24.04","id":"noble","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.1-cp310-abi3-musllinux_1_2_aarch64.whl

Download URL ozaru-0.3.1-cp310-abi3-musllinux_1_2_aarch64.whl
Size 898.5 kB
Tags CPython 3.10 Linux musl 1.2+ ARM64 abi3
SHA-256 checksum
How to use checksums
992322bf6e6c80156d6911d8ef996d9cf1082c647803036842b553e957816640
BLAKE2b-256 checksum
How to use checksums
5d3cd0441a638bdad2d62d5e16f6b352ddf9e098531f6920d0bbaffc9215f8b7
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":"24.04","id":"noble","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.1-cp310-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl

Download URL ozaru-0.3.1-cp310-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Size 740.8 kB
Tags CPython 3.10 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
3a994efb83f14e65d463f175693596125d20c002a7cfd1f7de084818ecaa37ca
BLAKE2b-256 checksum
How to use checksums
8ef80a3ca5f30ca311bc8949c5fd1e0c43f530ec2447775c973765e9349d9cc6
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":"24.04","id":"noble","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.1-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl

Download URL ozaru-0.3.1-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
Size 720.7 kB
Tags CPython 3.10 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
c51b4d4ca93014db0175bbd129824eda4b21dd867a28aac1caee53b1fdd3969f
BLAKE2b-256 checksum
How to use checksums
2aff65dafe14ede33e614d3e8a1ac865cef108d4a83e8568a8a3e616c5bc97c3
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":"24.04","id":"noble","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.1-cp310-abi3-macosx_11_0_arm64.whl

Download URL ozaru-0.3.1-cp310-abi3-macosx_11_0_arm64.whl
Size 634.5 kB
Tags CPython 3.10 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
523c7d13cb9fdd3809a7be3f9ce557e4fa90f42fae4cc33341aca0388be5e8c1
BLAKE2b-256 checksum
How to use checksums
c32d49cc1ca399bef50625fde044118c760fbde141db0f0e60c298b431ada309
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":"24.04","id":"noble","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.1-cp310-abi3-macosx_10_12_x86_64.whl

Download URL ozaru-0.3.1-cp310-abi3-macosx_10_12_x86_64.whl
Size 682.6 kB
Tags CPython 3.10 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
0e1bd0212ac3743593570688eb7d670d10116fdc212844732ada967ccadf2522
BLAKE2b-256 checksum
How to use checksums
70ceb0a783fa8c823781ef78e3c537f2c6316c6a8ee6d6d54d3987f884c1481d
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":"24.04","id":"noble","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.1

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