No project description provided
Project description
nshconfig-extra
nshconfig-extra is a collection of additional configuration types for the nshconfig library. It extends the functionality of nshconfig by providing support for file handling across various storage systems (local, remote SSH, URLs, cloud storage) through a unified interface.
Installation
To install nshconfig-extra, use the following command:
pip install nshconfig-extra
If you want to use this library with optional dependencies (SSH support), you can install the extra dependencies using the following command:
pip install nshconfig-extra[extra]
Usage
File Handling
The package provides a unified interface for working with files from various sources.
Base File Config
All file configurations inherit from BaseFileConfig, which provides a consistent interface:
from nshconfig_extra import BaseFileConfig, AnyFileConfig, resolve_file_config, open_file_config
# Type alias for any file reference
# AnyFileConfig = str | Path | BaseFileConfig
# Helper functions for working with any file type
path = resolve_file_config("path/to/file.txt") # Returns a Path object
with open_file_config("path/to/file.txt", "rt") as f:
content = f.read()
CachedPathConfig
The CachedPathConfig class provides access to files from various sources with automatic caching:
from nshconfig_extra import CachedPathConfig
# Access a file from Hugging Face Hub
config = CachedPathConfig(uri="https://huggingface.co/user/repo/resolve/main/file.txt")
local_path = config.resolve() # Downloads if needed, returns local cached path
with config.open("rt") as f: # Opens the file directly
content = f.read()
# Access a file from S3
s3_config = CachedPathConfig(uri="s3://bucket/path/to/file.txt")
s3_path = s3_config.resolve()
# Local file with caching
local_config = CachedPathConfig(uri="/path/to/file.txt")
Supported URI types:
- Local file paths
- HTTP/HTTPS URLs
- S3 bucket paths (s3://...)
- GCS bucket paths (gs://...)
- Hugging Face Hub paths
SSH File Access
For accessing files on remote servers via SSH:
from nshconfig_extra import RemoteSSHFileConfig
# Using SSH URI
ssh_config = RemoteSSHFileConfig.from_uri("ssh://user:pass@hostname:22/path/to/file.txt")
# Using SSH config file (~/.ssh/config)
ssh_config = RemoteSSHFileConfig.from_ssh_config("host_alias", "/path/to/remote/file.txt")
# Direct connection
ssh_config = RemoteSSHFileConfig.from_direct_connection(
hostname="example.com",
remote_path="/path/to/file.txt",
username="user",
password="pass"
)
# Accessing the file
local_path = ssh_config.resolve() # Downloads to temporary location
with ssh_config.open("rt") as f: # Opens directly over SSH
content = f.read()
Contributing
Contributions to nshconfig-extra are welcome! If you encounter any issues or have suggestions for improvement, please open an issue or submit a pull request on the GitHub repository.
License
nshconfig-extra is open-source software licensed under the MIT License.
Acknowledgements
nshconfig-extra (and nshconfig) are heavily dependent on the Pydantic library for defining and validating configuration types. The file caching functionality leverages the cached-path library.
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 nshconfig_extra-0.9.3.tar.gz.
File metadata
- Download URL: nshconfig_extra-0.9.3.tar.gz
- Upload date:
- Size: 9.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.2 CPython/3.12.3 Linux/6.8.0-59-generic
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2e89ecf24e780e6b93b7c5d6dc2db7a4e6245cd3c559d5c75d12d99b52f4b769
|
|
| MD5 |
f8aef2df751cf614adc198a76b6622ac
|
|
| BLAKE2b-256 |
09282b1735cbf24a0484f5015ebc879c5a03007212d820b3a6c626e5489754ea
|
File details
Details for the file nshconfig_extra-0.9.3-py3-none-any.whl.
File metadata
- Download URL: nshconfig_extra-0.9.3-py3-none-any.whl
- Upload date:
- Size: 10.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.2 CPython/3.12.3 Linux/6.8.0-59-generic
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a336528cb698a1b83afaed58f33e342f0eb89ce50b5334df38c21a277e0228de
|
|
| MD5 |
57b07b42e6a2dccf744245c9fe3a2499
|
|
| BLAKE2b-256 |
25ee7f1ee0ebaacf1fb9292853643bc5b10459d8ce83e955c5e0faac0d09503a
|