Skip to main content

Subclass of a pathlib.Path object that does not allow traversal outside of a trusted root.

Project description

PathRoot

What is PathRoot?

A PathRoot object is a subclass of pathlib.Path. It takes an extra safe_root= keyword argument to set a trusted root, and prevents operations that traverse outside of the trusted root.

How do you use PathRoot?

You can initialize a PathRoot object like this:

from pathroot import PathRoot

root = PathRoot('/Users/foo/bar', safe_root='/Users/foo/bar')
root = PathRoot('/Users/foo/bar')  # This also works.

From there, you can do anything you can do with a Path object. For instance:

my_file = root / 'groceries.txt'  # This would work.
my_file = root / '..' / '..' / 'groceries.txt'  # This would raise a `PathOutsideRootError` exception.

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

pathroot-1.0.0.tar.gz (5.1 kB view details)

Uploaded Source

Built Distribution

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

pathroot-1.0.0-py3-none-any.whl (3.3 kB view details)

Uploaded Python 3

File details

Details for the file pathroot-1.0.0.tar.gz.

File metadata

  • Download URL: pathroot-1.0.0.tar.gz
  • Upload date:
  • Size: 5.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.13

File hashes

Hashes for pathroot-1.0.0.tar.gz
Algorithm Hash digest
SHA256 0c00afac52e335a5d6794043b8d9f830c28f9d8197383369ff301edf859e28eb
MD5 082e6610b3031b9e5448b2abb759cc91
BLAKE2b-256 347744612ef6bed154e9f722f525ac4b9bab32b7dfc06ec3b28340595e0959f0

See more details on using hashes here.

File details

Details for the file pathroot-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: pathroot-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 3.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.13

File hashes

Hashes for pathroot-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0efc17b0b98ae046d34ea05a0f0b54d0cf86c144f27099967a1e809bccc55e53
MD5 7bcd421558f021749aebe6a8c575a7eb
BLAKE2b-256 9d91f6ca66ff495494d27653d6625449b638c44e967783dc47ab650dc6b73a66

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