Phext
Welcome to the Pythonic port of phext.
This port is a downstream artifact that tracks the Rust-based implementation of Phext. See https://github.com/wbic16/libphext-rs for more details.
Getting Started
To use phext in your Python project, simply add phext as a dependency.
pip install phext
Refer to the tests folder for usage information.
import phext
from phext.coordinate import Coordinate
from phext.phext import Phext
phext = Phext()
test = "Hello\x17World"
coord = Coordinate.from_string("1.1.1/1.1.1/1.1.1")
scroll = phext.fetch(test, coord)
scrolls = phext.explode(test)
coord2 = Coordinate(1,1,1, 1,1,1, 1,1,2)
print(scroll + ", " + scrolls[coord2])
Development
The project uses uv. From the repository root:
uv sync
This creates .venv with phext installed from this checkout (editable) and the dev dependency group (pytest).
Test
uv run pytest
pytest comes from the dev group, so the tests run in the project's environment against this checkout. pyproject.toml also puts the checkout on pytest's path, so a pytest from somewhere else still tests this code rather than a phext it finds installed.
To time the core operations on a real file:
uv run python test/bench.py path/to/file.phext
It reports explode, implode, textmap, index, and fetch (of the last scroll). Name operations after the file to run only those, for example explode fetch.
Build
-
Set the new version in both
pyproject.tomlandphext/__init__.py. -
Build into an empty folder.
dist/holds older builds that are checked into git, anduv publishwould try to upload those too. Deleterelease-distfirst if it is left over from a previous release.uv build --out-dir release-dist
-
Check the package metadata, then import the wheel in a throwaway environment (use the version you just built):
uvx twine check release-dist/*
uv run --isolated --no-project --with release-dist/phext-0.3.2-py3-none-any.whl python -c "import phext; print(phext.__version__)"
Publish
uv publish release-dist/*
This needs a PyPI API token for the phext project: set UV_PUBLISH_TOKEN, or pass --token. To rehearse on TestPyPI first (it uses a separate account and token):
uv publish --publish-url https://test.pypi.org/legacy/ release-dist/*
Data Types
Coordinate: A 9-tuple of the form library.shelf.series/collection.volume.book/chapter.section.scroll. Represents the location of a given scroll of text within a larger phext file.Phext: The main entrypoint to interacting with phexts.fetch(buffer, coordinate): Fetches a scroll of text from the given serialized phext bufferphokenize(buffer): Extracts a list of positioned scrolls from the given phextappend_scroll(entry, location): Emits the delimiters and text required to insert the positioned scroll, entry, into a phext stream (starting from the given location).dephokenize(stack): Serializes a stack of positioned scrollsnormalize(str): Eliminates empty scrolls from a phext bufferupdate(buffer, coord, scroll, overwrite): Supports insert and update operations - places the scroll of text at the given coordinate, taking the current state of the buffer into accountinsert(buffer, coord, scroll): Inserts text at the end of the scroll located at coord within the bufferreplace(buffer, coord, scroll): Replaces the text located at coord within the bufferremove(buffer, coord): Removes the contents of the scroll located at coord within the bufferrange_replace(buffer, range, text): Removes scrolls located within the given range, without shifting content outside of the range - this differs from libphext-rs by design - a pair of missing methods needs to be added to resolve the conflictnext_scroll(buffer, coord): Selects the next scroll after the given coordinateget_subspace_coordinates(buffer, target): Retrieves the subspace offsets cooresponding to the given target coordinate within the buffermerge(left, right): Zipper merges two phextssubtract(left, right): Removes the scrolls from left that are present in right (as measured by coordinate matching)expand(buffer): Dimensional increment for each phext break found in the buffercontract(buffer): Dimensional decrement for each phext break found in the buffercreate_summary(buffer): Creates a one-line summary of a given scrollnavmap(urlbase, buffer): Creates an HTML navigation map of the given buffertextmap(buffer): Creates a text-based navigation map of the given bufferchecksum(buffer): Computes an xxh3_128 hash of a given scrollmanifest(buffer): Computes a hierarchical hash of the given phextsoundex_v1(buffer): Computes a hierarchical soundex of the given phextsoundex_internal(buffer): Computes a low-level soundex of a given scrollexplode(buffer): Explodes a phext into a dictionary of Coordinate -> strimplode(hash): Implodes a dictionary of Coordinate -> str back into a phextindex_phokens(buffer): Computes the offsets of each scroll in the given phextindex(buffer): Computes a hierarchical map of scroll offsets in phext formatoffset(buffer, coord): Computes the offset of a specific scroll in the given phext
PositionedScroll: A pair ofCoordinateand a scroll of text.Range: A pair of coordinates denoting an inclusive range across subspace
Metadata
Release files for phext 0.3.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| phext-0.3.2.tar.gz | 77.7 kB | Without provenance | Details for phext-0.3.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| phext-0.3.2-py3-none-any.whl | Python 3 | none | any | Details for phext-0.3.2-py3-none-any.whl |
Total release size: 87.4 kB
Release files / phext-0.3.2.tar.gz
| Download URL | phext-0.3.2.tar.gz |
|---|---|
| Size | 77.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
bec96b4145ae03a14f8798e3b059bbb4725ef9b5251e03c43f8385b062a5c2b1
|
|
BLAKE2b-256 checksum How to use checksums |
9ea8841a29a91eef704f8f46f9f927a98223da55711a3d03ee0c91a0ea43f1d7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.8.4
|
Release files / phext-0.3.2-py3-none-any.whl
| Download URL | phext-0.3.2-py3-none-any.whl |
|---|---|
| Size | 9.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d2177c66f0211bfbb91715fae26e16a7c75e1bcd7229dfcd366fec2f5cae6693
|
|
BLAKE2b-256 checksum How to use checksums |
f9da306e347fb0550c488bd6d052b6d47fe02a21deaa981e9b5c8a7848cc7645
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.8.4
|
Security for phext 0.3.2
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.