urlpath-filereader
Version: 1.2.0
Author: Маг Ильяс DOMA (MagIlyasDOMA)
Email: magilyas.doma.09@list.ru
GitHub: https://github.com/MagIlyasDOMA/urlpath-filereader
Описание
urlpath-filereader — это Python-библиотека для удобного чтения файлов как из локальной файловой системы, так и из URL-адресов. Библиотека автоматически определяет кодировку файлов и поддерживает широкий спектр режимов открытия файлов.
Установка
Установите пакет через pip:
pip install urlpath-filereader
Или добавьте в requirements.txt:
urlpath-filereader==1.2.0
Зависимости
requestschardet>=2.0.0pathlike-typing
Основные функции
detect_encoding(file_path)
Определяет кодировку файла с помощью chardet.
Параметры:
file_path(PathLike): путь к файлу
Возвращает:
str: предполагаемая кодировка файла
is_url(source)
Проверяет, является ли источник URL-адресом.
Параметры:
source(PathLike): путь или URL
Возвращает:
bool:True, если источник является валидным URL
read_file(source)
Читает содержимое файла или URL-адреса.
Параметры:
source(PathLike): путь к файлу или URL
Возвращает:
str: содержимое файла в виде строки
Исключения:
FileNotFoundError: если локальный файл не существуетrequests.exceptions.RequestException: при ошибке HTTP-запроса
create_file_from_url(source, encoding)
Создаёт локальную копию файла из URL.
Параметры:
source(PathLike): URL-адресencoding(str): кодировка для сохранения
Возвращает:
str: путь к созданному файлу
open_plus(source, mode='r', ..., auto_detect_encoding=False)
Универсальная функция для открытия файлов и URL.
Параметры:
source(PathLike): путь к файлу или URLmode(FileOpenMode): режим открытия файла (по умолчанию 'r')auto_detect_encoding(bool): автоматически определять кодировку (по умолчанию False)
Остальные параметры соответствуют стандартной функции open()
Возвращает:
Файловый объект
Поддерживаемые режимы открытия файлов (FileOpenMode)
Библиотека поддерживает все стандартные режимы открытия файлов Python, включая:
'r','w','a','x'- Комбинированные режимы:
'r+','w+','a+','x+' - Текстовые режимы:
'rt','wt','at','xt' - Устаревшие режимы:
'U','rU', и др.
Полный список доступен в коде библиотеки.
Примеры использования
Чтение локального файла
from urlpath_filereader import read_file
content = read_file('example.txt')
print(content)
Чтение файла из URL
from urlpath_filereader import read_file
url_content = read_file('https://example.com/file.txt')
print(url_content)
Определение кодировки файла
from urlpath_filereader import detect_encoding
encoding = detect_encoding('example.txt')
print(f'Кодировка файла: {encoding}')
Открытие файла с автоматическим определением кодировки
from urlpath_filereader import open_plus
with open_plus('example.txt', auto_detect_encoding=True) as f:
content = f.read()
Создание локальной копии файла из URL
from urlpath_filereader import create_file_from_url
local_path = create_file_from_url('https://example.com/data.txt', 'utf-8')
print(f'Файл сохранён: {local_path}')
Обработка ошибок
- При чтении несуществующего локального файла выбрасывается
FileNotFoundError - При ошибках HTTP-запросов выбрасываются исключения из библиотеки
requests - При проблемах с кодировкой могут возникать
UnicodeDecodeError
Совместимость
- Python: >=3.10
- ОС: Независимая (Windows, Linux, macOS)
Лицензия
Проект распространяется под лицензией MIT. Подробности см. в файле LICENSE в репозитории.
Поддержка и обратная связь
По вопросам и предложениям обращайтесь:
- GitHub Issues: https://github.com/MagIlyasDOMA/urlpath-filereader/issues
- Email: magilyas.doma.09@list.ru
Metadata
Release files for urlpath-filereader 1.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| urlpath_filereader-1.2.0.tar.gz | 5.8 kB | Without provenance | Details for urlpath_filereader-1.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| urlpath_filereader-1.2.0-py3-none-any.whl | Python 3 | none | any | Details for urlpath_filereader-1.2.0-py3-none-any.whl |
Total release size: 12.1 kB
Release files / urlpath_filereader-1.2.0.tar.gz
| Download URL | urlpath_filereader-1.2.0.tar.gz |
|---|---|
| Size | 5.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d0637ab0bb28e7d680b7b30a766f5bbbc1587472c3bac67560715d8b4202bdfa
|
|
BLAKE2b-256 checksum How to use checksums |
b997653f4f63e462bb8eb79df6864fc4fffdf1fcf3544f0320c444934e59cfaa
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.2
|
Release files / urlpath_filereader-1.2.0-py3-none-any.whl
| Download URL | urlpath_filereader-1.2.0-py3-none-any.whl |
|---|---|
| Size | 6.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
bbcae5ae6ffdc624eae334b7aea74e97ba103c482b9badae2e20159ac898202b
|
|
BLAKE2b-256 checksum How to use checksums |
bbb7a2da77c8312e22d8ecbfa26f97c41a1af975bb74bf4b06b266c9c0635704
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.2
|
Security for urlpath-filereader 1.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.