Skip to main content

txtar

txtar is a Python reimplementation of Go's txtar format, a tool for bundling and managing multiple text files in a single archive.

Features

  • Parse txtar formatted text into structured data.
  • Serialize structured data back into txtar format.
  • Unpack txtar archives into the file system.

Usage

In unit tests

from pathlib import Path
import os

def test_my_function():
    # Define the txtar structure for sysfs-like files
    txtar_content = """
-- sys/class/thermal/thermal_zone0/temp --
55000
-- sys/class/power_supply/BAT0/capacity --
45
-- sys/block/sda/size --
1024000
"""

    with MockFS.from_string(txtar_content):
        assert os.path.exists("/sys/class/thermal/thermal_zone0/temp")
        assert os.path.exists("/sys/class/power_supply/BAT0/capacity")
        assert os.path.exists("/sys/block/sda/size")

        assert Path("/sys/block/sda/size").exists()

Reading a file

from txtar import TxTar

content = "..."  # txtar formatted string
archive = TxTar.parse(content)

Serializing to txtar Format

from txtar import TxTar, File

archive = TxTar(
    comments=["Example txtar archive"],
    files=[File(name="example.txt", lines=["Hello", "World"])]
)
content = archive.serialize()

Unpacking an Archive

from pathlib import Path
from txtar import TxTar

archive = TxTar.parse("...")
archive.unpack_in(Path("/path/to/unpack"))

Development

  • Install dependencies: poetry install
  • Run tests with pytest.

Releasing

poetry publish --build --username __token__ --password $PYPI_PASSWORD

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

Built distribution (wheel)

Table of built distributions (wheels) for txtar 0.1.1
File Interpreter ABI Platform
txtar-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 5.8 kB

Release files / txtar-0.1.1.tar.gz

Download URL txtar-0.1.1.tar.gz
Size 2.9 kB
Tags Source
SHA-256 checksum
How to use checksums
d1c0065e8538cd891518fa3f703fdf8f6e2a1be59032ee8c9602118de0a73726
BLAKE2b-256 checksum
How to use checksums
f25a74eeed94bc8babf0a2b472d6869e8b792e106cef1bbdce0187778d7196d0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.14 CPython/3.11.4 Linux/6.2.0-32-generic

Release files / txtar-0.1.1-py3-none-any.whl

Download URL txtar-0.1.1-py3-none-any.whl
Size 2.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ed21701cd8418466cf60387c0eac4d300cfccf0de2aa7309850f0790946c3f6a
BLAKE2b-256 checksum
How to use checksums
b4a203ac1dd484b8fab77fed0bf72fcf52768a987f101b828078a93cd237e872
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.14 CPython/3.11.4 Linux/6.2.0-32-generic

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 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