Metadata-Version: 2.4
Name: config-versioned
Version: 0.2.0
Summary: Settings and file I/O management using a configuration YAML file
Author-email: Nathaniel Henry <nat@henryspatialanalysis.com>
License: MIT License
        
        Copyright (c) 2026 Henry Spatial Analysis
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
        
Project-URL: Homepage, https://github.com/henryspatialanalysis/versioning
Project-URL: Bug Tracker, https://github.com/henryspatialanalysis/versioning/issues
Keywords: versioning,config,yaml,file-io,data-pipeline
Classifier: Programming Language :: Python :: 3
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: pyyaml>=6.0
Provides-Extra: pandas
Requires-Dist: pandas>=1.3; extra == "pandas"
Provides-Extra: geo
Requires-Dist: geopandas>=0.12; extra == "geo"
Provides-Extra: raster
Requires-Dist: rasterio>=1.3; extra == "raster"
Provides-Extra: xarray
Requires-Dist: xarray>=2022.3; extra == "xarray"
Provides-Extra: dbfread
Requires-Dist: dbfread>=2.0; extra == "dbfread"
Provides-Extra: excel
Requires-Dist: openpyxl>=3.0; extra == "excel"
Provides-Extra: all
Requires-Dist: pandas>=1.3; extra == "all"
Requires-Dist: openpyxl>=3.0; extra == "all"
Requires-Dist: geopandas>=0.12; extra == "all"
Requires-Dist: rasterio>=1.3; extra == "all"
Requires-Dist: xarray>=2022.3; extra == "all"
Requires-Dist: dbfread>=2.0; extra == "all"
Provides-Extra: docs
Requires-Dist: sphinx>=7.0; extra == "docs"
Requires-Dist: furo>=2023.9.10; extra == "docs"
Provides-Extra: dev
Requires-Dist: pandas>=1.3; extra == "dev"
Requires-Dist: openpyxl>=3.0; extra == "dev"
Requires-Dist: pytest>=7.0; extra == "dev"
Requires-Dist: pytest-cov>=4.0; extra == "dev"
Dynamic: license-file

# config-versioned

A Python package for YAML-based configuration management in data pipelines, with versioned directory support and automatic file I/O by extension.

## Installation

```bash
pip install config-versioned
```

Install optional extras for specific file formats:

```bash
pip install config-versioned[pandas]   # CSV, TSV, Excel, Stata
pip install config-versioned[geo]      # Shapefiles, GeoJSON, GeoPackage, etc.
pip install config-versioned[raster]   # GeoTIFF, rasterio formats
pip install config-versioned[xarray]   # NetCDF
pip install config-versioned[dbfread]  # DBF files
pip install config-versioned[all]      # All of the above
```

## Quick Start

### 1. Create a config YAML file

```yaml
# project_config.yaml
project_name: 'my_analysis'

directories:
  raw_data:
    versioned: false
    path: '~/data/raw'
    files:
      input_table: 'records.csv'

  results:
    versioned: true
    path: '~/data/results'
    files:
      output_table: 'processed.csv'
      summary: 'summary.txt'

versions:
  results: 'v1'
```

### 2. Load the config

```python
from config_versioned import Config

cfg = Config('project_config.yaml')
```

### 3. Access settings

```python
cfg.get('project_name')           # 'my_analysis'
cfg.get('versions', 'results')    # 'v1'
cfg.get()                         # full config dict
```

### 4. Build paths

```python
# Non-versioned: returns ~/data/raw
cfg.get_dir_path('raw_data')

# Versioned: returns ~/data/results/v1
cfg.get_dir_path('results')

# With a custom version override
cfg.get_dir_path('results', custom_version='v2')

# Full file path
cfg.get_file_path('raw_data', 'input_table')   # ~/data/raw/records.csv
cfg.get_file_path('results', 'output_table')   # ~/data/results/v1/processed.csv
```

All path methods return `pathlib.Path` objects.

### 5. Read and write files

```python
import pandas as pd

# Read a file (path resolved from config)
df = cfg.read('raw_data', 'input_table')

# Process data
processed = df.head(10)

# Write results (directory must exist)
cfg.write(processed, 'results', 'output_table')
cfg.write(['Summary: 10 rows written\n'], 'results', 'summary')

# Write the config itself to the results directory
cfg.write_self('results')
```

### 6. Override versions at load time

```python
# Run the same pipeline with a new version
cfg_v2 = Config('project_config.yaml', versions={'results': 'v2'})
cfg_v2.get_dir_path('results')  # ~/data/results/v2
```

## Standalone autoread / autowrite

```python
from config_versioned import autoread, autowrite

# Read by extension
df = autoread('data/records.csv')
config = autoread('config.yaml')
lines = autoread('notes.txt')

# Write by extension
autowrite(df, 'output/results.csv')
autowrite({'key': 'value'}, 'output/config.yaml')
autowrite(['line one\n', 'line two\n'], 'output/notes.txt')
```

## Supported File Extensions

| Format | Extensions | Requires |
|--------|-----------|---------|
| CSV / TSV | csv, tsv, gz, bz2 | `pandas` |
| Excel | xls, xlsx | `pandas`, `openpyxl` |
| Stata | dta | `pandas` |
| DBF | dbf | `dbfread` |
| YAML | yaml, yml | *(core)* |
| Text | txt | *(core)* |
| Shapefile / Vector | shp, geojson, gpkg, fgb, gml, kml, and more | `geopandas` |
| Raster | tif, geotiff | `rasterio` |
| NetCDF | nc | `xarray` |

For raster files, `autoread` returns `{"data": np.ndarray, "profile": dict}` and `autowrite` accepts that same structure (or a `(data, profile)` tuple).

## Example Config File

A bundled example is included with the package:

```python
import importlib.resources as r
from config_versioned import Config

path = str(r.files("config_versioned") / "data" / "example_config.yaml")
cfg = Config(path)
```
