Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nshconfig_extra-0.10.0.tar.gz (9.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

nshconfig_extra-0.10.0-py3-none-any.whl (10.2 kB view details)

Uploaded Python 3

File details

Details for the file nshconfig_extra-0.10.0.tar.gz.

File metadata

  • Download URL: nshconfig_extra-0.10.0.tar.gz
  • Upload date:
  • Size: 9.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.3 CPython/3.12.3 Linux/6.8.0-60-generic

File hashes

Hashes for nshconfig_extra-0.10.0.tar.gz
Algorithm Hash digest
SHA256 b09b2a6a31f7b2778c45beba272fae6e36103cc856965a56f7a64d6c0e66a4a4
MD5 eec17c5ad624ebed38e3ca2911712fcd
BLAKE2b-256 f1867527911d7ecc203c07e882623a5ce9a8a040b883b058096020c5019e6e73

See more details on using hashes here.

File details

Details for the file nshconfig_extra-0.10.0-py3-none-any.whl.

File metadata

  • Download URL: nshconfig_extra-0.10.0-py3-none-any.whl
  • Upload date:
  • Size: 10.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.3 CPython/3.12.3 Linux/6.8.0-60-generic

File hashes

Hashes for nshconfig_extra-0.10.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6077d74082c5c2bfebec87ec93b92933950037e3016af65194edb9ae5fe37a83
MD5 bba6cdf3af7a8825f8343e73c02409da
BLAKE2b-256 9fb397ae7584807e2da38aa55524d722a75820dd52069a96389b1f7c8d30ccbd

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page