Skip to main content

A Python package for representing filesystem paths as a sequence of verbs.

Project description

fspathverbs

A Python package for representing filesystem paths as a sequence of verbs.

What makes fspathverbs unique?

Unlike traditional libraries that treat filesystem paths as nouns, fspathverbs views filesystem paths as a sequence of verbs:

  • Root(root): Step to the root directory root.
  • Parent: Step to the parent directory.
  • Current: Step to the current directory.
  • Child(child): Step to the child child (file or directory).
import ntpath
import posixpath
from fspathverbs import Root, Parent, Current, Child, compile_to_fspathverbs

# NT path test cases
assert compile_to_fspathverbs(path='', split=ntpath.split) == [Current()]
assert compile_to_fspathverbs(path='C:\\Users\\Alice\\Documents', split=ntpath.split) == [
    Root(root='C:\\'),
    Child(child='Users'),
    Child(child='Alice'),
    Child(child='Documents')
]
assert compile_to_fspathverbs(path='D:notes\\todo.txt', split=ntpath.split) == [
    Root(root='D:'),
    Child(child='notes'),
    Child(child='todo.txt')
]
assert compile_to_fspathverbs(path='\\server\\share\\folder\\', split=ntpath.split) == [
    Root(root='\\'),
    Child(child='server'),
    Child(child='share'),
    Child(child='folder'),
    Current()
]
assert compile_to_fspathverbs(path='.\\subdir\\file', split=ntpath.split) == [
    Current(),
    Current(),
    Child(child='subdir'),
    Child(child='file')
]
assert compile_to_fspathverbs(path='..\\backup\\..\\archive', split=ntpath.split) == [
    Current(),
    Parent(),
    Child(child='backup'),
    Parent(),
    Child(child='archive')
]
# Absolute path with mixed slashes
assert compile_to_fspathverbs(path='C:/weird\\mix/format', split=ntpath.split) == [
    Root(root='C:/'),
    Child(child='weird'),
    Child(child='mix'),
    Child(child='format')
]
# UNC path with share, trailing slash
assert compile_to_fspathverbs(path='\\\\network-pc\\storage\\docs\\', split=ntpath.split) == [
    Root(root='\\\\network-pc\\storage\\'),
    Child(child='docs'),
    Current()
]
# Device path
assert compile_to_fspathverbs(path='\\\\.\\COM56\\logs', split=ntpath.split) == [
    Root(root='\\\\.\\COM56\\'),
    Child(child='logs')
]

# POSIX path test cases
assert compile_to_fspathverbs(path='', split=posixpath.split) == [Current()]
assert compile_to_fspathverbs(path='/', split=posixpath.split) == [Root(root='/')]
assert compile_to_fspathverbs(path='/alpha/beta/gamma', split=posixpath.split) == [
    Root(root='/'),
    Child(child='alpha'),
    Child(child='beta'),
    Child(child='gamma')
]
assert compile_to_fspathverbs(path='delta/epsilon', split=posixpath.split) == [
    Current(),
    Child(child='delta'),
    Child(child='epsilon')
]
assert compile_to_fspathverbs(path='/foo/./bar/../baz/', split=posixpath.split) == [
    Root(root='/'),
    Child(child='foo'),
    Current(),
    Child(child='bar'),
    Parent(),
    Child(child='baz'),
    Current()
]
assert compile_to_fspathverbs(path='./theta/../iota', split=posixpath.split) == [
    Current(),
    Current(),
    Child(child='theta'),
    Parent(),
    Child(child='iota')
]

Installation

pip install fspathverbs

What are the benefits?

  • Correctness: Traditional path simplification (e.g., collapsing foo/../bar to bar) can be incorrect if foo is a file and not a directory. fspathverbs allows you to validate each navigation step as it happens, ensuring your code reflects the actual structure of the filesystem.
  • Security: Treating paths as a series of verbs helps prevent path traversal vulnerabilities (such as escaping a sandbox via ..). Each verb can be checked against permissions and boundaries, stopping exploits before they occur.
  • Clarity: Verbs are explicit, making path handling transparent and auditable.
  • Novelty: To our knowledge, this is the first open-source library that represents filesystem paths as a sequence of verbs, rather than just strings or string wrappers. This fills a long-standing gap in filesystem path modeling.

Contributing

Contributions are welcome! Please submit pull requests or open issues on the GitHub repository.

License

This project is licensed under the MIT License.

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

fspathverbs-0.1.0a0.tar.gz (4.2 kB view details)

Uploaded Source

Built Distribution

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

fspathverbs-0.1.0a0-py2.py3-none-any.whl (4.4 kB view details)

Uploaded Python 2Python 3

File details

Details for the file fspathverbs-0.1.0a0.tar.gz.

File metadata

  • Download URL: fspathverbs-0.1.0a0.tar.gz
  • Upload date:
  • Size: 4.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.9

File hashes

Hashes for fspathverbs-0.1.0a0.tar.gz
Algorithm Hash digest
SHA256 eab83e9da7ca1e4789f0a738f8b13997b03986a0c13e8e4b3d4ebb59627950b3
MD5 90fcb2c624cf9a0e5aa3b0888928ee93
BLAKE2b-256 d7e18353e5be2cb0a4ac41aceb1eabf5c3b67260a667f81c878ce449b3a5852f

See more details on using hashes here.

File details

Details for the file fspathverbs-0.1.0a0-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for fspathverbs-0.1.0a0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 73f66498c6a1418c1e04a6a80feb11ec99a7b229c3c59d58e878c23ca0261076
MD5 d3d89b3bfccd5ba16a05666de007695f
BLAKE2b-256 11a8286a7276a3a4f54eee2873f0db7f1599a3859e104ec2caef090328cc7774

See more details on using hashes here.

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