Metadata-Version: 2.4
Name: cfgio
Version: 1.0.2
Summary: Unified async JSON/YAML config I/O with routed access for files and in-memory data, featuring atomic saves and thread-offloaded parsing.
Project-URL: Homepage, https://github.com/moh-dehghan/configio
Project-URL: Repository, https://github.com/moh-dehghan/configio
Project-URL: Issues, https://github.com/moh-dehghan/configio/issues
Author-email: Moh-Dehghan <m.dehghan.2003@outlook.com>
License: MIT License
        
        Copyright (c) 2025 Moh-Dehghan
        Email: M.Dehghan.2003@outlook.com
        GitHub: https://github.com/Moh-Dehghan/ConfigIO
        
        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.
License-File: LICENSE
Keywords: async,asyncio,atomic-write,config,file-io,in-memory,json,loader,mapping,nested,path-routing,persistence,pyroute,routing,settings,yaml
Classifier: Development Status :: 4 - Beta
Classifier: Framework :: AsyncIO
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Internet
Classifier: Topic :: Software Development :: Libraries
Requires-Python: >=3.10
Requires-Dist: aiofiles>=23.0.0
Requires-Dist: pyroute>=1.0.0
Requires-Dist: pyyaml>=6.0.0
Description-Content-Type: text/markdown

# ConfigIO ⚙️
[![PyPI version](https://badge.fury.io/py/cfgio.svg)](https://pypi.org/project/cfgio/)
[![Python Versions](https://img.shields.io/pypi/pyversions/cfgio.svg)](https://pypi.org/project/cfgio/)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)

`configio` provides a single, loader‑driven API that can either work on files (FILE
mode) or on in‑memory Python documents (DATA mode). Nested access and updates are
addressed using [`pyroute.Route`](https://pypi.org/project/pyroute/). Parsing and
persistence are delegated to lightweight backends (`configio.jsonio`, `configio.yamlio`)
that perform best‑effort atomic writes.

---

## Features ✨

- **Two loaders, one API**: operate on disk (`loader=FILE`) or on in‑memory objects
  (`loader=DATA`) with the same methods.
- **Routed access**: immutable, hashable paths via `Route("a", "b", "c")`.
- **Async I/O**: all entry points are `async`.
- **Thread offload**: `threadsafe=True` offloads heavy parse/dump to a worker thread
  (primarily useful in FILE mode).
- **Atomic saves**: temp‑file + `os.replace(...)` pattern under the hood.
- **Strict codec**: `codec` is explicit (`Codec.JSON` or `Codec.YAML`)—no extension inference.

---

## Installation 📦

```bash
pip install cfgio -U
```

---

## Quick Start 🚀

```python
import asyncio
from configio import ConfigIO, Loader, Codec, Route
# Also you can import Route from pyroute package


async def main():
    # --- FILE mode (read from / write to disk) ---
    value = await ConfigIO.get(
        loader=Loader.FILE,
        codec=Codec.YAML,
        path="config.yml",
        route=Route("server", "port"),
    )
    print("server.port:", value)

    updated = await ConfigIO.set(
        loader=Loader.FILE,
        codec=Codec.JSON,
        path="config.json",
        route=Route("features", "beta"),
        value=True,
        overwrite_conflicts=True,  # create/overwrite missing/non-mapping parents as {}
        save=True,  # persist to disk
        threadsafe=True,  # offload parse/dump
    )
    print("updated FILE doc:", updated)

    # --- DATA mode (operate on an in-memory document) ---
    doc = {"app": {"theme": "light", "lang": "en"}}

    # Update in memory only
    doc = await ConfigIO.set(
        loader=Loader.DATA,
        data=doc,
        codec=Codec.YAML,
        route=Route("app", "theme"),
        value="dark",
        save=False,  # do NOT persist
    )

    # Optionally persist DATA mode to disk
    doc = await ConfigIO.set(
        loader=Loader.DATA,
        data=doc,
        codec=Codec.YAML,
        path="app.yml",
        route=Route("app", "lang"),
        value="fa-IR",
        save=True,  # requires path when loader=DATA
    )

    # Delete with drop semantics
    doc = await ConfigIO.delete(
        loader=Loader.DATA,
        data=doc,
        codec=Codec.YAML,
        route=Route("app", "theme"),
        drop=True,  # prune empty parents bottom-up
        save=False,
    )
    print("after delete:", doc)


if __name__ == "__main__":
    asyncio.run(main())
```

---

## Routing Cheatsheet 🧭

```python
from pyroute import Route

Route("a")                # ["a"]
Route("a", "b", "c")      # ["a"]["b"]["c"]
# Use hashable keys (strings, ints...) to traverse mapping-only structures.
```

---

## Path Types 🛣️

`PathType = Union[str, os.PathLike[str]]`  
At runtime, both plain strings and `os.PathLike` instances are accepted and validated.

---

## Example Configs 📄

**YAML**
```yaml
server:
  host: 127.0.0.1
  port: 8080
features:
  beta: false
```

**JSON**
```json
{
  "server": { "host": "127.0.0.1", "port": 8080 },
  "features": { "beta": false }
}
```

---

## License 📝

This project is licensed under the MIT License – see the [LICENSE](LICENSE) file for details.

---

## Acknowledgements 🙏

- [`pyroute`](https://pypi.org/project/pyroute/) for clean route semantics.
