Skip to main content

MIT-licensed libary for parsing and creating fstab files

PyPI Read the Docs License

Features

  • Unlike Canonical’s fstab Python library, this actually works with Python 3 and does not have a cancerous license (GPLv3)

  • Small

Installation

pip3 install pyfstab

Examples

# Import the classes
from pyfstab import Fstab

# Read the file
with open("/etc/fstab", "r") as f:
    fstab = Fstab().read_file(f)

# List all devices/identifiers of fstab entries
for entry in fstab.entries:
    print(entry.device)

# List all mountpoints of CIFS mounts
for entry in fstab.entries_by_type["cifs"]:
    print(entry.dir)

# Print filesystem type for mount at /mnt/disk
print(fstab.entry_by_dir["/mnt/disk"].type)

# List all mount options for device UUID=123456
for entry in fstab.entries_by_device["UUID=123456"]:
    print(entry.options)

# Print Tag value for all entries with device defined as
# UUID=something or ID=something
for entry in fstab.entries:
    if entry.device_tag_type in {"UUID", "ID"}:
        print(entry.device_tag_value)

# Change device tag type from UUID= to ID=
entry.device_tag_type = "ID"

# Change device tag value from "123456" to "4321"
# (Changes from "ID=123456" to "ID=4321")
entry.device_tag_value = "4321"

# Print new device string (it's "ID=4321" now)
print(entry.device)

# Set both tag type and value at the same time in both valid ways
entry.device = ("UUID", "11223344")
entry.device = "UUID=11223344"

# Add an entry (does not update entries_by_device/type/dir)
# but it will be printed when formatting the fstab object
fstab.entries.append(
    Entry(
        "/dev/sdg4",
        "/mnt/disk",
        "ext4",
        "rw,relatime",
        0,
        0
    )
)

# Remove all entries except ext*
fstab.entries = [
    entry
    for entry in fstab.entries
    if entry.type.startswith("ext")
]

# Print and write the formatted fstab file
formatted = str(fstab)
print(formatted)
with open("/etc/myfstab", "w") as f:
    f.write(formatted)

Contributing

  • Send any issues to GitHub’s issue tracker.

  • Before sending a pull request, format it with Black (-Sl79)

  • Any changes must be updated to the documentation

  • All pull requests must be tested with tox (if you are using pyenv, add the installed versions for py35-py38 and pypy3 to .python-version at the root of this repository before running tox)

Metadata

Release files for pyfstab 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pyfstab 0.2.0
File Size Uploaded
pyfstab-0.2.0.tar.gz 6.2 kB Details

Built distribution (wheel)

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

Total release size: 12.5 kB

Release files / pyfstab-0.2.0.tar.gz

Download URL pyfstab-0.2.0.tar.gz
Size 6.2 kB
Tags Source
SHA-256 checksum
How to use checksums
5f0ceeef5c6356a5414ff44eaf578b774a3ff14cce901593ff25f8cb79b769f5
BLAKE2b-256 checksum
How to use checksums
397568453a33f32e5089a6cda22daa81ff0a41fec91b946ad2df20597881ef4b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.12 CPython/3.10.1 Linux/5.15.11-zen1-1-zen

Release files / pyfstab-0.2.0-py3-none-any.whl

Download URL pyfstab-0.2.0-py3-none-any.whl
Size 6.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
798bf5dda62007fe94a56f91a9dddec972cfca482527eba768651df8b64171c5
BLAKE2b-256 checksum
How to use checksums
fe493f8982ed4dd3a82eb54395bef717490129c75b20e8612cc2b6a1e52a0ea3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.12 CPython/3.10.1 Linux/5.15.11-zen1-1-zen

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files

0.1.1

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