Skip to main content

pathlib-like Path object for smb protocol

Project description

smb-path

Version PyPI - Version PyPI - Python Version
Project GitHub License PyPI - Status PyPI - Format PyPI - Implementation
CI GitHub Actions Workflow Status Test smb-path
Code PyPI - Types Checked with mypy Linting: Ruff Code style: black

pathlib-like Path object for smb protocol

Table of Contents

About

Many tools make use of pathlib.Path internally. This is a problem if the files are located on a fileshare. smb-path provides wrapper of Path which acts accordingly but using the SMB protocol for file operations instead of the local hosts file system. Atm. smb-path focuses on pure reading of the data. The SMB protocol implementation of smbprotocol is used.

All the utility functions of Path should work for SmbPath as well (like the / operator, with_suffix, parents, etc.).

Currently the following SMB dependent functions are implemented:

  • glob (experimental)
  • iterdir
  • mkdir
    • NOTE: param mode has currently no effect, it falls back to 755 !
  • open
    • and hence dependent funtions like read_bytes, etc.
  • stat
    • and hence dependent functions like lstat, is_file, is_dir, exists, etc.
  • rename
  • replace
  • rmdir
  • symlink_to
  • unlink

Missing operations (throwing exception) with current version (and questionable whether all of them will come) are:

  • chmod
  • hardlink_to
  • resolve
    • Resolves symlinks and makes relative paths absolute, latter is useless for SmbPath
  • touch

Installation

pip install smb-path

Usage

smb-path just needs to be installed. After the installation, you just use Path() to instantiate a SmbPath. It is checked whether the provided path string applies to the regex pattern r"(//|\\\\)([a-z0-9_-]+)((\.[a-z0-9_-]+)*)(\.[a-z]+){1}".

The path string

  • must start with // or \\
  • must continue with a server name, a-z, 0-9 and _, - allowed, eg. filshr33
  • optionally an arbitrary number of periods separated by a ., a-z, 0-9, _, - allowed, eg. .us.dieterscompany
  • must continue with an url closing with . then a-z, eg. .com
  • can contain trailing fileshare names, directories or files, eg. /myShare/myDir/myFile.txt

Hence //filshr33.us.dieterscompany.com/myShare/myDir/myFile.txt would be a valid SMB path.

If the pattern does not match, a Path object like you are used to it is returned (WindowsPath or PosixPath).

SMB Configuration

Use smbclient.ClientConfig to configure the SMB connection. Eg. smbclient.ClientConfig(username="itsme", password="myPW"). Refer to smbprotocol for further information.

Compatibility

smbprotocol is platform agnostic since it does not care about the path separator.

Tested with installation into a python -m venv virtual environment.

License

smb-path is distributed under the terms of 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 Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

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

smb_path-0.6.2-py3-none-any.whl (7.1 kB view details)

Uploaded Python 3

File details

Details for the file smb_path-0.6.2-py3-none-any.whl.

File metadata

  • Download URL: smb_path-0.6.2-py3-none-any.whl
  • Upload date:
  • Size: 7.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-httpx/0.28.1

File hashes

Hashes for smb_path-0.6.2-py3-none-any.whl
Algorithm Hash digest
SHA256 ee24518f848c8ab0167895069e7845874eebebcc96d78fc6ee366f2c0178ebca
MD5 d6ddda033a6a5781be51cc18150b9344
BLAKE2b-256 a01bef7a38ef4f72d5c0c2f5ccd6f773f2bfa3b42ff3604e120a73059f53c058

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