Skip to main content

PathLike Typing Library / Библиотека PathLike Typing


English Documentation

Overview

pathlike-typing is a lightweight Python library that provides a standardized type alias PathLike for representing file system paths in type annotations. It simplifies working with path objects by unifying Path (from pathlib) and str types under a single type hint.

Installing

pip install pathlike-typing

Version

Current version: 1.0.0

Usage

from pathlib import Path
from pathlike_typing import PathLike

# Use PathLike in type annotations
def read_file(path: PathLike) -> str:
    # Both Path objects and strings are accepted
    with open(path, 'r') as f:
        return f.read()

# Both will work:
read_file(Path("/home/user/file.txt"))
read_file("/home/user/file.txt")

Type Alias

The library provides one main export:

  • PathLike: Type alias for Union[Path, str]

Exports

__all__ = ["PathLike", "__version__"]

Why Use This Library?

  1. Consistency: Standardizes path type annotations across your codebase
  2. Clarity: Makes function signatures clearer about what types of path arguments are accepted
  3. Compatibility: Works seamlessly with both pathlib.Path objects and traditional string paths
  4. Lightweight: Minimal dependencies and overhead

License

MIT License - See LICENSE file for details.


Документация на русском языке

Обзор

pathlike-typing — это облегчённая библиотека Python, предоставляющая стандартизированный псевдоним типа PathLike для представления путей к файловой системе в аннотациях типов. Она упрощает работу с объектами путей, объединяя типы Path (из pathlib) и str под единым указанием типа.

Установка

pip install pathlike-typing

Версия

Текущая версия: 1.0.0

Использование

from pathlib import Path
from pathlike_typing import PathLike

# Используйте PathLike в аннотациях типов
def read_file(path: PathLike) -> str:
    # Поддерживаются как объекты Path, так и строки
    with open(path, 'r') as f:
        return f.read()

# Поддерживаются оба варианта:
read_file(Path("/home/user/file.txt"))
read_file("/home/user/file.txt")

Псевдоним типа

Библиотека предоставляет один основной экспорт:

  • PathLike: Псевдоним типа для Union[Path, str]

Экспорт

__all__ = ["PathLike", "__version__"]

Зачем использовать эту библиотеку?

  1. Единообразие: Стандартизирует аннотации типов путей в вашей кодовой базе.
  2. Ясность: Делает сигнатуры функций более понятными для определения типов принимаемых аргументов путей.
  3. Совместимость: Без проблем работает как с объектами pathlib.Path, так и с традиционными строковыми путями.
  4. Легковесность: Минимальные зависимости и накладные расходы.

Лицензия

Лицензия MIT — подробности см. в файле LICENSE.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pathlike_typing-1.0.0.tar.gz (4.1 kB view details)

Uploaded Source

Built Distribution

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

pathlike_typing-1.0.0-py3-none-any.whl (4.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pathlike_typing-1.0.0.tar.gz
  • Upload date:
  • Size: 4.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for pathlike_typing-1.0.0.tar.gz
Algorithm Hash digest
SHA256 7adc47fc4565cde49053c8bcd1e08a06dfb46e1a0789ed94c15ce9b663e4bb96
MD5 3f54840ca0a76f33f4f4c4024611ae13
BLAKE2b-256 922cb3f00636edf4d4b727e5f34e49ba3f4154588a360bffcce5fb046e532963

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pathlike_typing-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ed656aadf7ea7b8f2145fc37f00cdff1ddf666f676b7306a173a8cdef701b449
MD5 9c688d60e2adb5e83a0486ca01a80c10
BLAKE2b-256 56da9c97ed4ccf2ceabeed509750df0557446603a130ff6923aa899c232fdfad

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page