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.

Metadata

Release files for pathlike-typing 1.0.0

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

Source distribution (sdist)

Source distribution for pathlike-typing 1.0.0
File Size Uploaded
pathlike_typing-1.0.0.tar.gz 4.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pathlike-typing 1.0.0
File Interpreter ABI Platform
pathlike_typing-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 8.4 kB

Release files / pathlike_typing-1.0.0.tar.gz

Download URL pathlike_typing-1.0.0.tar.gz
Size 4.1 kB
Tags Source
SHA-256 checksum
How to use checksums
7adc47fc4565cde49053c8bcd1e08a06dfb46e1a0789ed94c15ce9b663e4bb96
BLAKE2b-256 checksum
How to use checksums
922cb3f00636edf4d4b727e5f34e49ba3f4154588a360bffcce5fb046e532963
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.0

Release files / pathlike_typing-1.0.0-py3-none-any.whl

Download URL pathlike_typing-1.0.0-py3-none-any.whl
Size 4.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ed656aadf7ea7b8f2145fc37f00cdff1ddf666f676b7306a173a8cdef701b449
BLAKE2b-256 checksum
How to use checksums
56da9c97ed4ccf2ceabeed509750df0557446603a130ff6923aa899c232fdfad
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.0

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files

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