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.5.tar.gz (5.5 MB 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.5-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.5-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.5-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.5-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.5-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.5-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.5-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.5-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.5.tar.gz.

File metadata

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

File hashes

Hashes for pybtrfs-0.5.5.tar.gz
Algorithm Hash digest
SHA256 f1a112b3804b754978f9768ac9c9d866c9123ed7b02d98ec3a1b1808a675dd5c
MD5 bdd91ccc7f36d799beab421ca0636ca7
BLAKE2b-256 fcce5d9be757184b121ea95cfa4ec71c672f8791891ae04f5ce9ff7bb12d2d28

See more details on using hashes here.

Provenance

The following attestation bundles were made for pybtrfs-0.5.5.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.5-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pybtrfs-0.5.5-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 0b740827b08a225cd00a011208ef539bab8bdad0e2da3d0170b1539f18d3f40b
MD5 f357e43f637f08a55010a4d5bee18b2b
BLAKE2b-256 9a341241f8f84a3185592adbf5100fb71dd7a0ceb00f5a15600754df89619696

See more details on using hashes here.

Provenance

The following attestation bundles were made for pybtrfs-0.5.5-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.5-cp313-cp313-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for pybtrfs-0.5.5-cp313-cp313-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 6fee2afe03ce99ae474eade1d117152b8c95ae780b434e66eebe6b7bc56fd7a8
MD5 b675bd68ad05b3cfbc0e8177aaa01bb4
BLAKE2b-256 839efcad637ce035520a828d445bf705eca054c2f367bde9ab727fbd1abcfed2

See more details on using hashes here.

Provenance

The following attestation bundles were made for pybtrfs-0.5.5-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.5-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pybtrfs-0.5.5-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 ca684126a5d69c1b0b9756c171ee2377fcb6b217bedc4fb2ce5a58292b4c7c65
MD5 e40ff4ce035349ca872af1511348a0c3
BLAKE2b-256 85ff9da89e529df43b586a73432d60d44f075b8a983b155efec0d775bf61ab19

See more details on using hashes here.

Provenance

The following attestation bundles were made for pybtrfs-0.5.5-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.5-cp312-cp312-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for pybtrfs-0.5.5-cp312-cp312-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 88908176f85758df6eb94067e7b6faae53b3f1647365e345147d3cf387ea3286
MD5 5a9c17d445dfbb6a8c90ce7ec7169fb8
BLAKE2b-256 f33d61807c54a951525a76a06f0f2d05583ef7d22beb00cc4d033439032e94e8

See more details on using hashes here.

Provenance

The following attestation bundles were made for pybtrfs-0.5.5-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.5-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pybtrfs-0.5.5-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 14c547fc0c715bbb0204d84f5527237ac645600b7a04267ed16c877713ec2a5c
MD5 413e305398e50051ec7eb29050b65e39
BLAKE2b-256 e48c9a0ea1fb17f569364555e708395d62ff8c69f29ce15d8651a13be0861301

See more details on using hashes here.

Provenance

The following attestation bundles were made for pybtrfs-0.5.5-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.5-cp311-cp311-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for pybtrfs-0.5.5-cp311-cp311-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 5e97bc8afc12f9dca9b5ed429bba38e038bbc8a3e9da31c658f7eb28b574c2b7
MD5 4aad4d0174fa3a15654a1dad32c0c38f
BLAKE2b-256 89a6bc209acef726bdea763a6f22ce33c1714d7804aae788eebfe38c42efc5a1

See more details on using hashes here.

Provenance

The following attestation bundles were made for pybtrfs-0.5.5-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.5-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pybtrfs-0.5.5-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 0f034130f29bc2e1d606606931d322775635332ba43655d40c6b345ee3f3cb8e
MD5 bf80b63fb4f98b01ada01ab480fc4345
BLAKE2b-256 69fb26afa742fe785469979e12c91cb03379057a8db00237e8ecdb31e4848cae

See more details on using hashes here.

Provenance

The following attestation bundles were made for pybtrfs-0.5.5-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.5-cp310-cp310-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for pybtrfs-0.5.5-cp310-cp310-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 21bf083ec15867d8bc7474059acc9e0ac042348d06b8a1ebed65ae521b420cd9
MD5 fbfb42cb764e75af9a9612b3f7d320d1
BLAKE2b-256 5c8e6cce5f5260a3ad07a8110ae54a7d12dc3832b6edfec46061beb78403c823

See more details on using hashes here.

Provenance

The following attestation bundles were made for pybtrfs-0.5.5-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