Metadata-Version: 2.5
Name: pybiocfilecache
Version: 0.8.1
Summary: File based cache for resources and metadata
Project-URL: Homepage, https://github.com/BiocPy/pybiocfilecache
Project-URL: Documentation, https://biocpy.github.io/pybiocfilecache
Project-URL: Repository, https://github.com/BiocPy/pybiocfilecache
Project-URL: Bug Tracker, https://github.com/BiocPy/pybiocfilecache/issues
Author-email: Jayaram Kancherla <jayaram.kancherla@gmail.com>
License: The MIT License (MIT)
        
        Copyright (c) 2021 Genentech, Inc.
        
        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: AUTHORS.md
License-File: LICENSE.txt
Keywords: biocfilecache,cache,file-cache,resource-management,sqlite
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Science/Research
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
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: Programming Language :: Python :: 3.14
Classifier: Topic :: Scientific/Engineering :: Bio-Informatics
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Requires-Python: >=3.9
Requires-Dist: biocframe
Requires-Dist: sqlalchemy
Provides-Extra: testing
Requires-Dist: pytest; extra == 'testing'
Requires-Dist: pytest-cov; extra == 'testing'
Requires-Dist: setuptools; extra == 'testing'
Description-Content-Type: text/markdown

[![PyPI-Server](https://img.shields.io/pypi/v/pyBiocFileCache.svg)](https://pypi.org/project/pyBiocFileCache/)
![Unit tests](https://github.com/BiocPy/pybiocfilecache/actions/workflows/run-tests.yml/badge.svg)
![R and Python Interop](https://github.com/BiocPy/pybiocfilecache/actions/workflows/r-interop-tests.yml/badge.svg)

# pyBiocFileCache

`pyBiocFileCache` is a Python package that provides a file caching system with resource validation, expiration management, and SQLite-backed metadata. Compatible with the [BiocFileCache R package](https://github.com/Bioconductor/BiocFileCache).

## Installation

Install from [PyPI](https://pypi.org/project/pyBiocFileCache/):

```bash
pip install pybiocfilecache
```

## Quick Start

```python
from pybiocfilecache import BiocFileCache

# Initialize cache
cache = BiocFileCache("path/to/cache/directory")

# Add a file to cache
resource = cache.add("myfile", "path/to/file.txt")

# Retrieve a file from cache
resource = cache.get("myfile")

# Use the cached file
print(resource["rpath"])  # Path to cached file
```

## Advanced Usage

### Configuration

```python
from datetime import timedelta
from pathlib import Path

from pybiocfilecache import BiocFileCache, CacheConfig

# Create custom configuration
config = CacheConfig(
    cache_dir=Path("cache_directory"),
    cleanup_interval=timedelta(days=7),
)

# Initialize cache with configuration
cache = BiocFileCache(config=config)
```

### Resource Management

```python
from datetime import datetime, timedelta, timezone

# Add file with expiration
resource = cache.add(
    "myfile",
    "path/to/file.txt",
    expires=datetime.now(timezone.utc) + timedelta(days=30),
)

# Immediate lookup without waiting on missing files
record = cache.get(rid="BFC1", wait=False)

# List resources
resources = cache.list_resources()

# Search resources (exact or substring match)
results = cache.search("myfile", field="rname")

# Update resource by name or rid
cache.update("myfile", "path/to/new_file.txt")
cache.update(rid="BFC1", fpath="path/to/new_file.txt")

# Remove resource by name or rid
cache.remove("myfile")
```

### Cache Statistics and Maintenance

```python
# Get cache statistics
stats = cache.get_stats()
print(stats)

# Clean up expired resources
removed_count = cache.cleanup()

# Verify integrity of cached files
valid, invalid = cache.verify_cache()

# Purge entire cache
cache.purge()
```
