Skip to main content

Python API for Pagefind

Project description

pagefind

An async python API for the pagefind binary.

Installation

python3 -m pip install 'pagefind[bin]'
python3 -m pagefind --help

Usage

import asyncio
import json
import logging
import os
from pagefind.index import PagefindIndex, IndexConfig

logging.basicConfig(level=os.environ.get("LOG_LEVEL", "INFO"))
log = logging.getLogger(__name__)
html_content = (
    "<html>"
    "  <body>"
    "    <main>"
    "      <h1>Example HTML</h1>"
    "      <p>This is an example HTML page.</p>"
    "    </main>"
    "  </body>"
    "</html>"
)


def prefix(pre: str, s: str) -> str:
    return pre + s.replace("\n", f"\n{pre}")


async def main():
    config = IndexConfig(
        root_selector="main", logfile="index.log", output_path="./output", verbose=True
    )
    async with PagefindIndex(config=config) as index:
        log.debug("opened index")
        new_file, new_record, new_dir = await asyncio.gather(
            index.add_html_file(
                content=html_content,
                url="https://example.com",
                source_path="other/example.html",
            ),
            index.add_custom_record(
                url="/elephants/",
                content="Some testing content regarding elephants",
                language="en",
                meta={"title": "Elephants"},
            ),
            index.add_directory("./public"),
        )
        print(prefix("new_file    ", json.dumps(new_file, indent=2)))
        print(prefix("new_record  ", json.dumps(new_record, indent=2)))
        print(prefix("new_dir     ", json.dumps(new_dir, indent=2)))

        files = await index.get_files()
        for file in files:
            print(prefix("files", f"{len(file['content']):10}B {file['path']}"))


if __name__ == "__main__":
    asyncio.run(main())

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pagefind-1.5.0b2.tar.gz (46.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pagefind-1.5.0b2-py3-none-any.whl (10.1 kB view details)

Uploaded Python 3

File details

Details for the file pagefind-1.5.0b2.tar.gz.

File metadata

  • Download URL: pagefind-1.5.0b2.tar.gz
  • Upload date:
  • Size: 46.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pagefind-1.5.0b2.tar.gz
Algorithm Hash digest
SHA256 b838d2c5a4ec5836294fa54af66b4210568a97635093c43b915d67ccb589378f
MD5 2be25fc2bf277fc7008a206ca89338ee
BLAKE2b-256 c81bd88d8d7fe3628e705c154b5b14bd4ddc5204b5fd155ce1aee48099fc6485

See more details on using hashes here.

Provenance

The following attestation bundles were made for pagefind-1.5.0b2.tar.gz:

Publisher: release.yml on Pagefind/pagefind

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pagefind-1.5.0b2-py3-none-any.whl.

File metadata

  • Download URL: pagefind-1.5.0b2-py3-none-any.whl
  • Upload date:
  • Size: 10.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pagefind-1.5.0b2-py3-none-any.whl
Algorithm Hash digest
SHA256 2798b4f75134ba57197b93a6d7eb8e726be8d0eb86932f5ace72c0e5c8f1e637
MD5 2809b553dd0916ff51eda3086f2187e4
BLAKE2b-256 8bff7f5f9a551f53c0c2f247d216b0e9ba6f50954abb6266edc495a1e2f4082a

See more details on using hashes here.

Provenance

The following attestation bundles were made for pagefind-1.5.0b2-py3-none-any.whl:

Publisher: release.yml on Pagefind/pagefind

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page