# nshsnap
nshsnap is a Python library for creating and managing snapshots of Python projects and environments. It's particularly useful for scenarios where you need to preserve the exact state of your code and dependencies, such as when running machine learning training jobs on cluster systems like SLURM.
## Motivation
When running long-running jobs or experiments, especially in distributed environments, it's critical to maintain consistency in your codebase. Small changes in your project files can lead to crashes or inconsistent results in ongoing runs. nshsnap addresses this issue by allowing you to take a full snapshot of your main development package, preserving the code state at that moment.
This tool was originally created to solve issues encountered when running ML training jobs on SLURM. It enables you to:
1. Capture the current state of your project
2. Ensure reproducibility across multiple runs
3. Isolate changes in your development environment from active jobs
## Installation
You can install nshsnap using pip:
```bash
pip install nshsnap
```
## Usage
### Programmatic Usage
Here's a basic example of how to use nshsnap in your Python code:
```python
from nshsnap import snapshot
# Create a snapshot with default settings
snapshot_info = snapshot()
# Or, create a snapshot with custom configuration
snapshot_info = snapshot(
modules=["my_project", "my_other_module"],
editable_modules=True
)
print(f"Snapshot created at: {snapshot_info.snapshot_dir}")
print(f"Modules included: {', '.join(snapshot_info.modules)}")
```
### Command Line Usage
nshsnap also provides a command-line interface:
```bash
# Snapshot all editable packages in the current environment
nshsnap --editables
# Snapshot specific modules
nshsnap --modules my_project my_other_module
# Specify a custom snapshot directory
nshsnap --editables --dir /path/to/snapshot/directory
# Get help
nshsnap --help
```
### Activating and Using Snapshots
After creating a snapshot, all you need to do is prepend the snapshot directory to your `PYTHONPATH` to activate the snapshot environment:
```bash
export PYTHONPATH=/path/to/snapshot:$PYTHONPATH
```
You can also activate or execute commands within the snapshot environment using our helper scripts:
```bash
# Activate the snapshot environment
source /path/to/snapshot/.bin/activate
# Execute a command within the snapshot environment
/path/to/snapshot/.bin/execute python my_script.py
```
## Features
- Snapshot editable packages and specified modules
- Preserve exact state of code and dependencies
- Easy activation and execution within snapshot environments
- Integration with version control systems (respects .gitignore)
- Metadata storage for snapshot information
## Requirements
- Python 3.10+
- git
- rsync
## Contributing
Contributions to nshsnap are welcome! Please feel free to submit a Pull Request.
## License
[MIT License](LICENSE)
Raw data
{
"_id": null,
"home_page": "https://github.com/nimashoghi/nshsnap",
"name": "nshsnap",
"maintainer": null,
"docs_url": null,
"requires_python": "<4.0,>=3.9",
"maintainer_email": null,
"keywords": null,
"author": "Nima Shoghi",
"author_email": "nimashoghi@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/d2/a1/5d498e179f6424c3ec5584e76690fb723f3ae5ced2d750f604864da7c3e2/nshsnap-0.14.1.tar.gz",
"platform": null,
"description": "# nshsnap\n\nnshsnap is a Python library for creating and managing snapshots of Python projects and environments. It's particularly useful for scenarios where you need to preserve the exact state of your code and dependencies, such as when running machine learning training jobs on cluster systems like SLURM.\n\n## Motivation\n\nWhen running long-running jobs or experiments, especially in distributed environments, it's critical to maintain consistency in your codebase. Small changes in your project files can lead to crashes or inconsistent results in ongoing runs. nshsnap addresses this issue by allowing you to take a full snapshot of your main development package, preserving the code state at that moment.\n\nThis tool was originally created to solve issues encountered when running ML training jobs on SLURM. It enables you to:\n\n1. Capture the current state of your project\n2. Ensure reproducibility across multiple runs\n3. Isolate changes in your development environment from active jobs\n\n## Installation\n\nYou can install nshsnap using pip:\n\n```bash\npip install nshsnap\n```\n\n## Usage\n\n### Programmatic Usage\n\nHere's a basic example of how to use nshsnap in your Python code:\n\n```python\nfrom nshsnap import snapshot\n\n# Create a snapshot with default settings\nsnapshot_info = snapshot()\n\n# Or, create a snapshot with custom configuration\nsnapshot_info = snapshot(\n modules=[\"my_project\", \"my_other_module\"],\n editable_modules=True\n)\n\nprint(f\"Snapshot created at: {snapshot_info.snapshot_dir}\")\nprint(f\"Modules included: {', '.join(snapshot_info.modules)}\")\n```\n\n### Command Line Usage\n\nnshsnap also provides a command-line interface:\n\n```bash\n# Snapshot all editable packages in the current environment\nnshsnap --editables\n\n# Snapshot specific modules\nnshsnap --modules my_project my_other_module\n\n# Specify a custom snapshot directory\nnshsnap --editables --dir /path/to/snapshot/directory\n\n# Get help\nnshsnap --help\n```\n\n### Activating and Using Snapshots\n\nAfter creating a snapshot, all you need to do is prepend the snapshot directory to your `PYTHONPATH` to activate the snapshot environment:\n\n```bash\nexport PYTHONPATH=/path/to/snapshot:$PYTHONPATH\n```\n\nYou can also activate or execute commands within the snapshot environment using our helper scripts:\n\n```bash\n# Activate the snapshot environment\nsource /path/to/snapshot/.bin/activate\n\n# Execute a command within the snapshot environment\n/path/to/snapshot/.bin/execute python my_script.py\n```\n\n## Features\n\n- Snapshot editable packages and specified modules\n- Preserve exact state of code and dependencies\n- Easy activation and execution within snapshot environments\n- Integration with version control systems (respects .gitignore)\n- Metadata storage for snapshot information\n\n## Requirements\n\n- Python 3.10+\n- git\n- rsync\n\n## Contributing\n\nContributions to nshsnap are welcome! Please feel free to submit a Pull Request.\n\n## License\n\n[MIT License](LICENSE)\n",
"bugtrack_url": null,
"license": null,
"summary": null,
"version": "0.14.1",
"project_urls": {
"Homepage": "https://github.com/nimashoghi/nshsnap"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "f49516ce7e31c1a44a6ef91a059f4edbe60966f831e48605586fe9a5105ca052",
"md5": "4967cc127bf8f77e6b380d791e401a17",
"sha256": "84bbf285fad715bf712c53370e94a06c395f2cd291a1399489e4d5c6ba3eb299"
},
"downloads": -1,
"filename": "nshsnap-0.14.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "4967cc127bf8f77e6b380d791e401a17",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<4.0,>=3.9",
"size": 25779,
"upload_time": "2025-06-19T01:24:28",
"upload_time_iso_8601": "2025-06-19T01:24:28.856758Z",
"url": "https://files.pythonhosted.org/packages/f4/95/16ce7e31c1a44a6ef91a059f4edbe60966f831e48605586fe9a5105ca052/nshsnap-0.14.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "d2a15d498e179f6424c3ec5584e76690fb723f3ae5ced2d750f604864da7c3e2",
"md5": "ce9e3d50df5b50b7985546b7879c6008",
"sha256": "7ee0e4f4fb7e84c08c4ce8e6c4868a425cd47155aa0da836a0a5959f7b1e635b"
},
"downloads": -1,
"filename": "nshsnap-0.14.1.tar.gz",
"has_sig": false,
"md5_digest": "ce9e3d50df5b50b7985546b7879c6008",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<4.0,>=3.9",
"size": 13792,
"upload_time": "2025-06-19T01:24:29",
"upload_time_iso_8601": "2025-06-19T01:24:29.967091Z",
"url": "https://files.pythonhosted.org/packages/d2/a1/5d498e179f6424c3ec5584e76690fb723f3ae5ced2d750f604864da7c3e2/nshsnap-0.14.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-06-19 01:24:29",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "nimashoghi",
"github_project": "nshsnap",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "nshsnap"
}