Skip to main content

Static Python bindings for btrfs ioctl operations

Project description

pybtrfs

Native Python bindings for btrfs — create filesystems, manage subvolumes and snapshots, mount and unmount. No shell commands, no subprocess, no runtime dependencies beyond libc.

Built as C extensions directly from vendored btrfs-progs source. Pre-built binary wheels are available on PyPI — no compiler needed.

Why not the existing btrfs package?

The btrfs package on PyPI requires libbtrfsutil installed as a system library. That means distro packages, broken virtualenvs, and pain on minimal containers or custom builds.

pybtrfs statically compiles everything from vendored source — the only build-time requirement is a C compiler and Python headers. The resulting .so files link only to libc.

All blocking operations (ioctl calls, sync, mkfs, mount/umount) release the GIL, so they can safely run in parallel from multiple threads without blocking the interpreter.

Requirements

  • Linux with btrfs support
  • Python 3.10+

Installation

Pre-built wheels for x86_64 and aarch64 (manylinux_2_28):

pip install pybtrfs

Releases with wheels are also available on GitHub.

To build from source (requires GCC and Python headers):

pip install .

Or with make:

make build      # compile extensions
make install    # pip install .

Usage

Subvolumes and snapshots

import pybtrfs

# Create a subvolume
pybtrfs.create_subvolume("/mnt/data/project")

# Snapshot before a risky operation
pybtrfs.create_snapshot("/mnt/data/project", "/mnt/data/project-snap",
                        read_only=True)

# Check snapshot relationship
src = pybtrfs.subvolume_info("/mnt/data/project")
snap = pybtrfs.subvolume_info("/mnt/data/project-snap")
assert snap.parent_uuid == src.uuid

# Clean up
pybtrfs.delete_subvolume("/mnt/data/project-snap")

List all subvolumes

with pybtrfs.SubvolumeIterator("/mnt/data", info=True) as it:
    for path, info in it:
        print(f"{path} (id={info.id}, gen={info.generation})")

Create a filesystem

from pybtrfs import mkfs, CsumType, RaidProfile

# Single device
result = mkfs("/dev/sdb", label="data", force=True)
print(result["uuid"])

# RAID1 mirror with xxhash checksums
result = mkfs("/dev/sdb", "/dev/sdc",
              data_profile=RaidProfile.RAID1,
              metadata_profile=RaidProfile.RAID1,
              csum_type=CsumType.XXHASH,
              force=True)

Mount and unmount

from pybtrfs import mount, umount, mount_data, MountFlags

mount("/dev/sdb", "/mnt/data",
      data=mount_data(compress="zstd", space_cache="v2"))

mount("/dev/sdb", "/mnt/readonly", flags=MountFlags.RDONLY)

umount("/mnt/data")

Error handling

import pybtrfs

try:
    pybtrfs.sync("/not/btrfs")
except pybtrfs.BtrfsUtilError as e:
    print(e.btrfsutil_errno)  # e.g. BtrfsUtilErrno.NOT_BTRFS
    print(e.errno)            # OS errno

API reference

The package ships with .pyi stubs — full signatures and docstrings are available via help(pybtrfs), help(pybtrfs.mkfs), help(pybtrfs.mount), and your IDE's autocomplete.

Testing

Tests require root and a mounted btrfs filesystem:

truncate -s 1G /tmp/btrfs.img
mkfs.btrfs /tmp/btrfs.img
mkdir -p ~/btrfs
mount /tmp/btrfs.img ~/btrfs

sudo BTRFS=~/btrfs PYTHONPATH=. pytest -v

License

GPL-2.0 — see LICENSE.

This project statically compiles code from btrfs-progs (GPL-2.0), including libbtrfsutil (LGPL-2.1) and substantial portions of the core btrfs-progs codebase (kernel-shared, mkfs, crypto, etc.) which are GPL-2.0. Since the resulting binaries are derivative works of GPL-2.0 code, this project is licensed under GPL-2.0 to comply with the upstream license terms.

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

pybtrfs-0.5.3.tar.gz (449.1 kB view details)

Uploaded Source

Built Distributions

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

pybtrfs-0.5.3-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (1.7 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

pybtrfs-0.5.3-cp313-cp313-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl (1.6 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.27+ ARM64manylinux: glibc 2.28+ ARM64

pybtrfs-0.5.3-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (1.7 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

pybtrfs-0.5.3-cp312-cp312-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl (1.6 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.27+ ARM64manylinux: glibc 2.28+ ARM64

pybtrfs-0.5.3-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (1.7 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

pybtrfs-0.5.3-cp311-cp311-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl (1.6 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.27+ ARM64manylinux: glibc 2.28+ ARM64

pybtrfs-0.5.3-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (1.7 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

pybtrfs-0.5.3-cp310-cp310-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl (1.6 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.27+ ARM64manylinux: glibc 2.28+ ARM64

File details

Details for the file pybtrfs-0.5.3.tar.gz.

File metadata

  • Download URL: pybtrfs-0.5.3.tar.gz
  • Upload date:
  • Size: 449.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pybtrfs-0.5.3.tar.gz
Algorithm Hash digest
SHA256 b12e347f3d03b224336a1407cd4598461577a8e36199686a866973437ba59287
MD5 fc4c3b768aebdaaa31f221d1e923b8c6
BLAKE2b-256 eba84cc87d763f656bbe10b8fea5f85c4ed592f1c0f74368be9f3d1871639094

See more details on using hashes here.

Provenance

The following attestation bundles were made for pybtrfs-0.5.3.tar.gz:

Publisher: wheels.yml on mosquito/pybtrfs

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

File details

Details for the file pybtrfs-0.5.3-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pybtrfs-0.5.3-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 86a1d866294d6ecb212d37ec12f80ee1c2a7a18c860fa397f091d568a5077e4f
MD5 73780d2ccbfcdabfa1534fafa037666a
BLAKE2b-256 1bb251805a06552a1d2eba0e005b13bd5098c9f0e606833cededd78d44aa5008

See more details on using hashes here.

Provenance

The following attestation bundles were made for pybtrfs-0.5.3-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl:

Publisher: wheels.yml on mosquito/pybtrfs

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

File details

Details for the file pybtrfs-0.5.3-cp313-cp313-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for pybtrfs-0.5.3-cp313-cp313-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 35394749ec983ee74f250391e696ee2688a26a9acd30ea22fc1cdafa897ba29a
MD5 f8dd66f0139086ae6653b0b98c9f8137
BLAKE2b-256 3f5fb0cb8ed64a4868e26209593e0c65bae2657608c6a831842cd517574748b5

See more details on using hashes here.

Provenance

The following attestation bundles were made for pybtrfs-0.5.3-cp313-cp313-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl:

Publisher: wheels.yml on mosquito/pybtrfs

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

File details

Details for the file pybtrfs-0.5.3-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pybtrfs-0.5.3-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 c55d80ad959095713955e6eeaf4226cc39f4b6370c582bd81dead52fbd418bc7
MD5 bed414b3dbe7aafb9fc1f7b2bfb71a81
BLAKE2b-256 4dfebd532330389efe8c09d4efe801c5124b92e1d4c82b519cebaea429e4e4c5

See more details on using hashes here.

Provenance

The following attestation bundles were made for pybtrfs-0.5.3-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl:

Publisher: wheels.yml on mosquito/pybtrfs

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

File details

Details for the file pybtrfs-0.5.3-cp312-cp312-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for pybtrfs-0.5.3-cp312-cp312-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 cc6e6b433b366ba57ecaaa52c0b532e0aedecc546a52ac777c8d4f100873dad5
MD5 2f8dd5e6069a5d4f6b172e3bb71b8050
BLAKE2b-256 a3c4c98d7440f21d5c9f335d800565f5c3c3376f24aced297f34ed4964161799

See more details on using hashes here.

Provenance

The following attestation bundles were made for pybtrfs-0.5.3-cp312-cp312-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl:

Publisher: wheels.yml on mosquito/pybtrfs

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

File details

Details for the file pybtrfs-0.5.3-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pybtrfs-0.5.3-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 c0cf3d0d5b7f8364b43cabd43cbd2f188320c2c9c82c2d27bcb72c2c9df17720
MD5 3024126a6c536162435999e1b8e71cc7
BLAKE2b-256 41b679301b553ec2b4a67cf4c5814fe1adb13de3828b727e7214d6a67c490da7

See more details on using hashes here.

Provenance

The following attestation bundles were made for pybtrfs-0.5.3-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl:

Publisher: wheels.yml on mosquito/pybtrfs

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

File details

Details for the file pybtrfs-0.5.3-cp311-cp311-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for pybtrfs-0.5.3-cp311-cp311-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 0778c764daeb56cdf479cc67505cf5080ab136d01aecb7f75c8e03734264d2c2
MD5 64e28862f8c165d82b71683af5f20cbc
BLAKE2b-256 595b8d7ff509f049b956048d3da4cee937c53bb1e566a90aecef23d486b63949

See more details on using hashes here.

Provenance

The following attestation bundles were made for pybtrfs-0.5.3-cp311-cp311-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl:

Publisher: wheels.yml on mosquito/pybtrfs

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

File details

Details for the file pybtrfs-0.5.3-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pybtrfs-0.5.3-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 e2415ffabbab54b18850df53934bc50f8bae2e91031a8341b6b64fe5f507a787
MD5 d515a25d50a35a57693d6df384b92d6b
BLAKE2b-256 5f1be476fcd1ea166ccd149cf54578f7d1a09b043231960408404beec7b5e8da

See more details on using hashes here.

Provenance

The following attestation bundles were made for pybtrfs-0.5.3-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl:

Publisher: wheels.yml on mosquito/pybtrfs

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

File details

Details for the file pybtrfs-0.5.3-cp310-cp310-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for pybtrfs-0.5.3-cp310-cp310-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 7f67e9e4e2d4304926f6a4a0610f1af49f28d325dd90c0997aacf77eac42ff0b
MD5 4452a1fe41cc0590aa89d637d10adf24
BLAKE2b-256 6e360909044069f66e5a4c48a081729d5b9344b34c59c548fbbc0ea570f97ffe

See more details on using hashes here.

Provenance

The following attestation bundles were made for pybtrfs-0.5.3-cp310-cp310-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl:

Publisher: wheels.yml on mosquito/pybtrfs

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