Skip to main content

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.

Metadata

Release files for nshconfig-extra 0.10.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 nshconfig-extra 0.10.0
File Size Uploaded
nshconfig_extra-0.10.0.tar.gz 9.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for nshconfig-extra 0.10.0
File Interpreter ABI Platform
nshconfig_extra-0.10.0-py3-none-any.whl Python 3 none any Details

Total release size: 20.1 kB

Release files / nshconfig_extra-0.10.0.tar.gz

Download URL nshconfig_extra-0.10.0.tar.gz
Size 9.9 kB
Tags Source
SHA-256 checksum
How to use checksums
b09b2a6a31f7b2778c45beba272fae6e36103cc856965a56f7a64d6c0e66a4a4
BLAKE2b-256 checksum
How to use checksums
f1867527911d7ecc203c07e882623a5ce9a8a040b883b058096020c5019e6e73
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.1.3 CPython/3.12.3 Linux/6.8.0-60-generic

Release files / nshconfig_extra-0.10.0-py3-none-any.whl

Download URL nshconfig_extra-0.10.0-py3-none-any.whl
Size 10.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6077d74082c5c2bfebec87ec93b92933950037e3016af65194edb9ae5fe37a83
BLAKE2b-256 checksum
How to use checksums
9fb397ae7584807e2da38aa55524d722a75820dd52069a96389b1f7c8d30ccbd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.1.3 CPython/3.12.3 Linux/6.8.0-60-generic

Release history Release notifications | RSS feed

This release

0.10.0 This release

2 release files

0.9.3

2 release files

0.9.2

2 release files

0.9.1

2 release files

0.9.0

2 release files

0.8.0

2 release files

0.7.3

2 release files

0.7.2

2 release files

0.7.1

2 release files

0.7.0

2 release files

0.6.2

2 release files

0.6.1

2 release files

0.6.0

2 release files

0.5.0

2 release files

0.4.0

2 release files

0.3.0

2 release files

0.2.0

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