Skip to main content

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
  • resolve
    • Resolves symlinks and makes relative paths absolute (latter is useless for SmbPath)
    • SMB Paths are always absolute
    • Currently just returns itself as is
  • rmdir
  • symlink_to
  • unlink
  • walk (Python 3.12+, as pathlib.Path.walk itself)
    • Supports in-place pruning of dirnames, top_down, on_error and follow_symlinks
    • Symlinks are treated like pathlib.Path.walk does, not like os.walk: with follow_symlinks=False a symlink pointing to a directory is reported in filenames

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

  • chmod
  • hardlink_to
  • 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]+)?".

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
  • a tld with . then a-z, eg. .com is optional
  • 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.

Metadata

Release files for smb-path 0.8.0

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

Built distribution (wheel)

Table of built distributions (wheels) for smb-path 0.8.0
File Interpreter ABI Platform
smb_path-0.8.0-py3-none-any.whl Python 3 none any Details

Release files / smb_path-0.8.0-py3-none-any.whl

Download URL smb_path-0.8.0-py3-none-any.whl
Size 8.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b504311ea33b9664e876bdbfbc563db4ff312da2ab186b5f68044a7f942a3944
BLAKE2b-256 checksum
How to use checksums
c2867c89346b950ce9f3dc15d52894f6fa4e38be65dbb3143c1672514b35b959
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via Hatch/1.17.0 {"ci":null,"cpu":"x86_64","distro":{"id":"noble","libc":{"lib":"glibc","version":"2.39"},"name":"Ubuntu","version":"24.04"},"implementation":{"name":"CPython","version":"3.12.3"},"installer":{"name":"hatch","version":"1.17.0"},"openssl_version":"OpenSSL 3.0.13 30 Jan 2024","python":"3.12.3","system":{"name":"Linux","release":"6.18.33.2-microsoft-standard-WSL2"}} HTTPX2/2.4.0

Release history Release notifications | RSS feed

This release

0.8.0 This release

1 release file

0.7.1

1 release file

0.7

1 release file

0.6.2

1 release file

0.6.1

1 release file

0.6.0

1 release file

0.5.1

1 release file

0.5.0

1 release file

0.4.0

1 release file

0.3.0

1 release file

0.2.0

1 release file

0.1.0

1 release file

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