Skip to main content

qalam

Correct, logical-order Arabic text extraction from digitally-born PDFs — without OCR.

Most PDF extractors hand back Arabic that is reversed, made of presentation forms, or silently corrupted at every ligature. qalam fixes the reading order, folds the shaped glyphs back to base letters, reconstructs multi-column reading order, and — when a page has no usable text layer — says so instead of returning plausible-looking garbage.

import qalam

text = qalam.extract_text("guide.pdf")

doc = qalam.Document("guide.pdf")
print(doc.confidence)          # 0.91
print(doc.pages_needing_ocr)   # [2, 3, 42, 43]

for page in doc:
    if page.needs_ocr:
        print(page.number, page.reasons)
    else:
        print(page.text)

Document.text omits pages that need OCR, so a scanned page never masquerades as a result. Read page.text directly if you want to see it anyway.

Structure, not just a string

A page is an ordered list of typed blocks. Each carries a kind, so you can branch on it without reaching for isinstance.

for block in doc.page(6).blocks:
    if block.kind == "table":
        for row in block.to_rows():      # the shape csv.writer wants
            print(row)
    elif block.kind == "image":
        block.save(block.file_name)
    else:
        print(block.text)

page.tables, page.images and page.lines are filtered views over the same blocks.

Tables know their reading order: on an Arabic page rows[0][0] is the rightmost cell, where a reader starts.

t = doc.page(5).tables[0]
t.row_count, t.column_count, t.confidence
t.rows[1][0].text          # 'المحافظات'

Images come back decoded — JPEG passed through untouched, everything else re-encoded as PNG — or with an unsupported_reason saying why not. Never silently dropped.

Each line carries its geometry and styling — line.direction, line.size, line.color, line.confidence — enough to rebuild a styled document.

page.tagged says whether the reading order came from the document's own structure tree rather than from geometry.

HTML output

open("out.html", "w").write(doc.to_html())

Reading order, headings inferred from type size, colour, tables with dir="rtl", images inlined. doc.heading_sizes() reports what the heading inference assumed.

For Markdown, convert the HTML with turndown or pandoc — Markdown cannot state text direction, so an Arabic table comes out mirrored.

Built on a Rust core; the GIL is released during extraction and rendering.

Metadata

Release files for qalam 0.1.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 qalam 0.1.1
File Size Uploaded
qalam-0.1.1.tar.gz 184.0 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for qalam 0.1.1
File
qalam-0.1.1-cp39-abi3-win_amd64.whl CPython 3.9 abi3 Windows x86-64 Details
qalam-0.1.1-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.9 abi3 Linux glibc 2.17+ x86-64 Details
qalam-0.1.1-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl CPython 3.9 abi3 Linux glibc 2.17+ ARM64 Details
qalam-0.1.1-cp39-abi3-macosx_11_0_arm64.whl CPython 3.9 abi3 macOS 11.0+ ARM64 Details
qalam-0.1.1-cp39-abi3-macosx_10_12_x86_64.whl CPython 3.9 abi3 macOS 10.12+ x86-64 Details

Total release size: 5.2 MB

Release files / qalam-0.1.1.tar.gz

Download URL qalam-0.1.1.tar.gz
Size 184.0 kB
Tags Source
SHA-256 checksum
How to use checksums
552e3078b2036c50cbeb9b9d09f0325e972f15cd5a5c06adacda062582baea24
BLAKE2b-256 checksum
How to use checksums
3286788e565e3afdacc1a80be7c74a1f028bfe5be40ab6287aedf55b4c3ce59a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 14, 2026.

Transparency log

Release files / qalam-0.1.1-cp39-abi3-win_amd64.whl

Download URL qalam-0.1.1-cp39-abi3-win_amd64.whl
Size 869.0 kB
Tags CPython 3.9 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
9082d337417b0992fcb9cc38130608cf39882f267609b6ae3111779aeb9783c6
BLAKE2b-256 checksum
How to use checksums
25c3b12f46653ab875840d2a5ab96474dc77e738d8f1362cae76a2dc58ec299e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 14, 2026.

Transparency log

Release files / qalam-0.1.1-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL qalam-0.1.1-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 1.1 MB
Tags CPython 3.9 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
0054f1086e24d63698efdbf73bde5fe3c3acc848cf10009ac7448f784dcc880b
BLAKE2b-256 checksum
How to use checksums
31915bbae2b5f1ac18fd273f5d6f18f9a6890cfb9e204c54a4282c742ac5d1b8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 14, 2026.

Transparency log

Release files / qalam-0.1.1-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL qalam-0.1.1-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 1.0 MB
Tags CPython 3.9 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
a0ad6a47ce3fc387560209686df3a5cdd3e8e501263d72cd66c0cf7d947de757
BLAKE2b-256 checksum
How to use checksums
8861bea4052ccd971f80e8365a121642b1996f80cc5c93c1cccfe4b9490151b6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 14, 2026.

Transparency log

Release files / qalam-0.1.1-cp39-abi3-macosx_11_0_arm64.whl

Download URL qalam-0.1.1-cp39-abi3-macosx_11_0_arm64.whl
Size 931.2 kB
Tags CPython 3.9 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
86dd255985ccdb8c394ccc420c72aa952772ed5942819d4e700eb81600d4243d
BLAKE2b-256 checksum
How to use checksums
7395e156d08b8f8dd7f1ed71e68a6019cbf29b3769d0cb3555a0cdb83916e55d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 14, 2026.

Transparency log

Release files / qalam-0.1.1-cp39-abi3-macosx_10_12_x86_64.whl

Download URL qalam-0.1.1-cp39-abi3-macosx_10_12_x86_64.whl
Size 998.1 kB
Tags CPython 3.9 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
b3078d3bbdd2d6b41f8bf6354989bcf7010919e60dc7b90f00007e0c76749fd6
BLAKE2b-256 checksum
How to use checksums
8eefb3ffe5ff5e91f9476df9d69313f377e4c94ee0da255b8381cfe62baba11f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 14, 2026.

Transparency log

Release history Release notifications | RSS feed

0.1.3

6 release files

This release

0.1.1 This release

6 release files

0.1.0

2 release files

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