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. pip install . is all you need.

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.

Requirements

  • Linux with btrfs support
  • Python 3.12+
  • GCC and Python headers for building (apt install python3-dev)

Installation

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.2.tar.gz (448.9 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.2-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.2-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.2-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.2-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.2-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.2-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.2-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.2-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.2.tar.gz.

File metadata

  • Download URL: pybtrfs-0.5.2.tar.gz
  • Upload date:
  • Size: 448.9 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.2.tar.gz
Algorithm Hash digest
SHA256 f86789160651059790c5d1622c2980cc373e794ce544f4274fd9c3f997d659ae
MD5 ac1fccca614402f4af03c565a526ad54
BLAKE2b-256 e185e550edab61bb6d5f7859065ea1770d78be869c3793735886ed6046cc7e96

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pybtrfs-0.5.2-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 626fd0a3c0dbabd4a3c8111d794a5cd4495acebbadc473f4817eb96145a30b22
MD5 af56d252de60954c9e5e3301bd19f705
BLAKE2b-256 49b82c784925b1144a69ca09fb14bf67aae44c34561da381b382be8e01af5fb1

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pybtrfs-0.5.2-cp313-cp313-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 d42c1ce9cb85feb2024df1afcaf836237bc4732d958020ec80a55747987129e5
MD5 7578d21756d95ed6518eb43e7799e08d
BLAKE2b-256 15887b2da085b5e5050bb24f743b78d6690cdaf14490bec6ed6f5c3c01983896

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pybtrfs-0.5.2-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 d7e05f75fcc1ba93c94851b217b92e84a7e54b319672e6046bee20e29bc9388a
MD5 1a11830a100c587782d9018c2060fca8
BLAKE2b-256 c70b1c5af2ba96c30188c5dd6d142055e5774d51c984a4188edbed5be216aecd

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pybtrfs-0.5.2-cp312-cp312-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 ad357779601780e6bbdf6fc7f1e37131250e4b569e270727a0b4343adf54cbf4
MD5 1146012cc6e2eea40a301c5f0dd1ee8d
BLAKE2b-256 c52de2d415443e0dde447e28124acd0e8c3af6fc66d767835599130d94ecb230

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pybtrfs-0.5.2-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 85a5407dfa646d77ba6e08f997d37dbcaffc698904f72cf6e83c3ffbd2e7afdb
MD5 2bb334af1856ebea74faa2d1a75d8a46
BLAKE2b-256 87ae649efaa1eeb8cee6b5599f1edff7f20993ec7690474940f31f6768bbc20d

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pybtrfs-0.5.2-cp311-cp311-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 f0e3a61c110ea92600c0d941ab0faeb10a2d99f5ce542172f0af6ff74a5b5d2a
MD5 55b7cd2a4f880837ccdf9f2a3ae3f55d
BLAKE2b-256 4f23bea23a3959392addc448cd0d3c5f4ea1d0566fed8317f5166102ae8425f6

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pybtrfs-0.5.2-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 e6af4429614d2e3ae84c1d72208e111e9cac7ebf346cf5fd04c89bee744a8038
MD5 335606b61362430de2473270eaac6bc9
BLAKE2b-256 f86165028a4d4a0024c948b5df1571d6384526913fdfa19552349cf4d7e4bf59

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pybtrfs-0.5.2-cp310-cp310-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 cc1ab460a14831299e233bb046c46c599ce5384ebb516f0202806e847882e761
MD5 3bc6c408bf8809668d88ef74e496b7ef
BLAKE2b-256 997d7ae912c938eb5832d49107e9aa9e2743a09aadd24389bedba531d79931df

See more details on using hashes here.

Provenance

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