Lightweight Python library providing PathLike type alias for path annotations
Project description
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 forUnion[Path, str]
Exports
__all__ = ["PathLike", "__version__"]
Why Use This Library?
- Consistency: Standardizes path type annotations across your codebase
- Clarity: Makes function signatures clearer about what types of path arguments are accepted
- Compatibility: Works seamlessly with both pathlib.Path objects and traditional string paths
- 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__"]
Зачем использовать эту библиотеку?
- Единообразие: Стандартизирует аннотации типов путей в вашей кодовой базе.
- Ясность: Делает сигнатуры функций более понятными для определения типов принимаемых аргументов путей.
- Совместимость: Без проблем работает как с объектами pathlib.Path, так и с традиционными строковыми путями.
- Легковесность: Минимальные зависимости и накладные расходы.
Лицензия
Лицензия MIT — подробности см. в файле LICENSE.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7adc47fc4565cde49053c8bcd1e08a06dfb46e1a0789ed94c15ce9b663e4bb96
|
|
| MD5 |
3f54840ca0a76f33f4f4c4024611ae13
|
|
| BLAKE2b-256 |
922cb3f00636edf4d4b727e5f34e49ba3f4154588a360bffcce5fb046e532963
|
File details
Details for the file pathlike_typing-1.0.0-py3-none-any.whl.
File metadata
- Download URL: pathlike_typing-1.0.0-py3-none-any.whl
- Upload date:
- Size: 4.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ed656aadf7ea7b8f2145fc37f00cdff1ddf666f676b7306a173a8cdef701b449
|
|
| MD5 |
9c688d60e2adb5e83a0486ca01a80c10
|
|
| BLAKE2b-256 |
56da9c97ed4ccf2ceabeed509750df0557446603a130ff6923aa899c232fdfad
|