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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pagefind-1.4.0.tar.gz.
File metadata
- Download URL: pagefind-1.4.0.tar.gz
- Upload date:
- Size: 9.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
881dea03b367e0d80084e2eba0979b25981ab7400f094a8cdddc5381928d8438
|
|
| MD5 |
85d492705dfae482840e390ba42c84d2
|
|
| BLAKE2b-256 |
2e7474ecc15aaeff30859c3e1164d6db796988602115d25a01a68851392ecfc6
|
Provenance
The following attestation bundles were made for pagefind-1.4.0.tar.gz:
Publisher:
release.yml on Pagefind/pagefind
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pagefind-1.4.0.tar.gz -
Subject digest:
881dea03b367e0d80084e2eba0979b25981ab7400f094a8cdddc5381928d8438 - Sigstore transparency entry: 455482041
- Sigstore integration time:
-
Permalink:
Pagefind/pagefind@8c3de15a6b5ab603985d98062e748463daf42d65 -
Branch / Tag:
refs/tags/v1.4.0 - Owner: https://github.com/Pagefind
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@8c3de15a6b5ab603985d98062e748463daf42d65 -
Trigger Event:
push
-
Statement type:
File details
Details for the file pagefind-1.4.0-py3-none-any.whl.
File metadata
- Download URL: pagefind-1.4.0-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.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7256d40eee4fe3e9bef553a2e1d00c546975bdacc64c510f6ddda874b47da01d
|
|
| MD5 |
494c4775fadfd39fd6f3f6461732fcd2
|
|
| BLAKE2b-256 |
832c474584536b91e3195ae11249c9384f09444770902db1186646234631bfba
|
Provenance
The following attestation bundles were made for pagefind-1.4.0-py3-none-any.whl:
Publisher:
release.yml on Pagefind/pagefind
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pagefind-1.4.0-py3-none-any.whl -
Subject digest:
7256d40eee4fe3e9bef553a2e1d00c546975bdacc64c510f6ddda874b47da01d - Sigstore transparency entry: 455482044
- Sigstore integration time:
-
Permalink:
Pagefind/pagefind@8c3de15a6b5ab603985d98062e748463daf42d65 -
Branch / Tag:
refs/tags/v1.4.0 - Owner: https://github.com/Pagefind
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@8c3de15a6b5ab603985d98062e748463daf42d65 -
Trigger Event:
push
-
Statement type: