archivefile


Namearchivefile JSON
Version 0.3.1 PyPI version JSON
download
home_pagehttps://ravencentric.github.io/archivefile
SummaryUnified interface for tar, zip, sevenzip, and rar files
upload_time2024-05-11 19:07:31
maintainerNone
docs_urlNone
authorRaventric
requires_python>=3.9
licenseUnlicense
keywords archive archivefile zipfile tarfile sevenzip rarfile
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            <br/>
<p align="center">
  <a href="https://github.com/Ravencentric/archivefile">
    <img src="https://raw.githubusercontent.com/Ravencentric/archivefile/main/docs/assets/logo.png" alt="Logo" width="400">
  </a>
  <p align="center">
    Unified interface for tar, zip, sevenzip, and rar files
  </p>
</p>

<div align="center">

[![PyPI - Version](https://img.shields.io/pypi/v/archivefile?link=https%3A%2F%2Fpypi.org%2Fproject%2Farchivefile%2F)](https://pypi.org/project/archivefile/)
![PyPI - Python Version](https://img.shields.io/pypi/pyversions/archivefile)
![License](https://img.shields.io/github/license/Ravencentric/archivefile)
![Checked with mypy](https://www.mypy-lang.org/static/mypy_badge.svg)
![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)

![GitHub Workflow Status (with event)](https://img.shields.io/github/actions/workflow/status/Ravencentric/archivefile/release.yml)
![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/ravencentric/archivefile/test.yml?label=tests)
[![codecov](https://codecov.io/gh/Ravencentric/archivefile/graph/badge.svg?token=B45ODO7TEY)](https://codecov.io/gh/Ravencentric/archivefile)

</div>

## Table Of Contents

* [About](#about)
* [Installation](#installation)
* [Docs](#docs)
* [License](#license)

## About

`archivefile` is a wrapper around [`tarfile`](https://docs.python.org/3/library/tarfile.html), [`zipfile`](https://docs.python.org/3/library/zipfile.html), [`py7zr`](https://github.com/miurahr/py7zr), and [`rarfile`](https://github.com/markokr/rarfile).

The above libraries are excellent when you are dealing with a single archive format but things quickly get annoying when you have a bunch of mixed archives such as `.zip`, `.7z`, `.cbr`, `.tar.gz`, etc because each library has a slightly different syntax and quirks which you need to deal with.

`archivefile` wraps the common methods from the above libraries to provide a unified interface that takes care of said differences under the hood. However, it's not as powerful as the libraries it wraps due to lack of support for features that are unique to a specific archive format and library.

## Installation

`archivefile` is available on [PyPI](https://pypi.org/project/archivefile/), so you can simply use [pip](https://github.com/pypa/pip) to install it.

1. Without optional dependencies:

    ```sh
    pip install archivefile
    ```

2. With optional dependencies:

    - Required for [`ArchiveFile.print_tree()`](https://ravencentric.github.io/archivefile/api-reference/archivefile/#archivefile.ArchiveFile.print_tree)

        ```sh
        pip install archivefile[bigtree]
        ```

    - Required for [`ArchiveFile.print_table()`](https://ravencentric.github.io/archivefile/api-reference/archivefile/#archivefile.ArchiveFile.print_table)

        ```sh
        pip install archivefile[rich]
        ```

3. With all dependencies:

    ```sh
    pip install archivefile[all]
    ```

## Usage

`archivefile` offers a single class called `ArchiveFile` to deal with various archive formats. Some examples are given below:

```py
from archivefile import ArchiveFile

with ArchiveFile("../source.zip") as archive:
    archive.extract("pyproject.toml", destination="./dest/") # Extract a single member by it's name
    archive.extractall(destination="./dest/") # Extract all members
    archive.get_member("pyproject.toml")  # Get the ArchiveMember object for the member by it's name
    archive.get_members()  # Retrieve all members from the archive as a tuple of ArchiveMember objects
    archive.get_names()  # Retrieve names of all members in the archive as a tuple of strings
    archive.read_bytes("pyproject.toml") # Read the contents of the member as bytes
    archive.read_text("pyproject.toml")  # Read the contents of the member as text
    archive.print_tree()  # Print the contents of the archive as a tree.
    archive.print_table()  # Print the contents of the archive as a table.

with ArchiveFile("../source.zip", "w") as archive:
    archive.write("foo.txt", arcname="bar.txt")  # Write foo.txt to the archive as bar.txt
    archive.writeall("./src/") # Recursively write the ./src/ directory to the archive
    archive.write_text("spam and eggs", arcname="recipe.txt") # Write a string to the archive as recipe.txt
    archive.write_bytes(b"0101001010100101", arcname="terminator.py")  # Write bytes to the archive as terminator.py
```

Refer to the [API reference](https://ravencentric.github.io/archivefile/api-reference/archivefile/) for more details.

## Docs

Checkout the complete documentation [here](https://ravencentric.github.io/archivefile/).

## License

Distributed under the [Unlicense](https://choosealicense.com/licenses/unlicense/) License. See [UNLICENSE](https://github.com/Ravencentric/archivefile/blob/main/UNLICENSE) for more information.

            

Raw data

            {
    "_id": null,
    "home_page": "https://ravencentric.github.io/archivefile",
    "name": "archivefile",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": null,
    "keywords": "archive, archivefile, zipfile, tarfile, sevenzip, rarfile",
    "author": "Raventric",
    "author_email": "78981416+Ravencentric@users.noreply.github.com",
    "download_url": "https://files.pythonhosted.org/packages/9a/9c/e6537b367daee3b1bcf64de162a1b28049d38b1eb005b142b904214b482e/archivefile-0.3.1.tar.gz",
    "platform": null,
    "description": "<br/>\n<p align=\"center\">\n  <a href=\"https://github.com/Ravencentric/archivefile\">\n    <img src=\"https://raw.githubusercontent.com/Ravencentric/archivefile/main/docs/assets/logo.png\" alt=\"Logo\" width=\"400\">\n  </a>\n  <p align=\"center\">\n    Unified interface for tar, zip, sevenzip, and rar files\n  </p>\n</p>\n\n<div align=\"center\">\n\n[![PyPI - Version](https://img.shields.io/pypi/v/archivefile?link=https%3A%2F%2Fpypi.org%2Fproject%2Farchivefile%2F)](https://pypi.org/project/archivefile/)\n![PyPI - Python Version](https://img.shields.io/pypi/pyversions/archivefile)\n![License](https://img.shields.io/github/license/Ravencentric/archivefile)\n![Checked with mypy](https://www.mypy-lang.org/static/mypy_badge.svg)\n![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)\n\n![GitHub Workflow Status (with event)](https://img.shields.io/github/actions/workflow/status/Ravencentric/archivefile/release.yml)\n![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/ravencentric/archivefile/test.yml?label=tests)\n[![codecov](https://codecov.io/gh/Ravencentric/archivefile/graph/badge.svg?token=B45ODO7TEY)](https://codecov.io/gh/Ravencentric/archivefile)\n\n</div>\n\n## Table Of Contents\n\n* [About](#about)\n* [Installation](#installation)\n* [Docs](#docs)\n* [License](#license)\n\n## About\n\n`archivefile` is a wrapper around [`tarfile`](https://docs.python.org/3/library/tarfile.html), [`zipfile`](https://docs.python.org/3/library/zipfile.html), [`py7zr`](https://github.com/miurahr/py7zr), and [`rarfile`](https://github.com/markokr/rarfile).\n\nThe above libraries are excellent when you are dealing with a single archive format but things quickly get annoying when you have a bunch of mixed archives such as `.zip`, `.7z`, `.cbr`, `.tar.gz`, etc because each library has a slightly different syntax and quirks which you need to deal with.\n\n`archivefile` wraps the common methods from the above libraries to provide a unified interface that takes care of said differences under the hood. However, it's not as powerful as the libraries it wraps due to lack of support for features that are unique to a specific archive format and library.\n\n## Installation\n\n`archivefile` is available on [PyPI](https://pypi.org/project/archivefile/), so you can simply use [pip](https://github.com/pypa/pip) to install it.\n\n1. Without optional dependencies:\n\n    ```sh\n    pip install archivefile\n    ```\n\n2. With optional dependencies:\n\n    - Required for [`ArchiveFile.print_tree()`](https://ravencentric.github.io/archivefile/api-reference/archivefile/#archivefile.ArchiveFile.print_tree)\n\n        ```sh\n        pip install archivefile[bigtree]\n        ```\n\n    - Required for [`ArchiveFile.print_table()`](https://ravencentric.github.io/archivefile/api-reference/archivefile/#archivefile.ArchiveFile.print_table)\n\n        ```sh\n        pip install archivefile[rich]\n        ```\n\n3. With all dependencies:\n\n    ```sh\n    pip install archivefile[all]\n    ```\n\n## Usage\n\n`archivefile` offers a single class called `ArchiveFile` to deal with various archive formats. Some examples are given below:\n\n```py\nfrom archivefile import ArchiveFile\n\nwith ArchiveFile(\"../source.zip\") as archive:\n    archive.extract(\"pyproject.toml\", destination=\"./dest/\") # Extract a single member by it's name\n    archive.extractall(destination=\"./dest/\") # Extract all members\n    archive.get_member(\"pyproject.toml\")  # Get the ArchiveMember object for the member by it's name\n    archive.get_members()  # Retrieve all members from the archive as a tuple of ArchiveMember objects\n    archive.get_names()  # Retrieve names of all members in the archive as a tuple of strings\n    archive.read_bytes(\"pyproject.toml\") # Read the contents of the member as bytes\n    archive.read_text(\"pyproject.toml\")  # Read the contents of the member as text\n    archive.print_tree()  # Print the contents of the archive as a tree.\n    archive.print_table()  # Print the contents of the archive as a table.\n\nwith ArchiveFile(\"../source.zip\", \"w\") as archive:\n    archive.write(\"foo.txt\", arcname=\"bar.txt\")  # Write foo.txt to the archive as bar.txt\n    archive.writeall(\"./src/\") # Recursively write the ./src/ directory to the archive\n    archive.write_text(\"spam and eggs\", arcname=\"recipe.txt\") # Write a string to the archive as recipe.txt\n    archive.write_bytes(b\"0101001010100101\", arcname=\"terminator.py\")  # Write bytes to the archive as terminator.py\n```\n\nRefer to the [API reference](https://ravencentric.github.io/archivefile/api-reference/archivefile/) for more details.\n\n## Docs\n\nCheckout the complete documentation [here](https://ravencentric.github.io/archivefile/).\n\n## License\n\nDistributed under the [Unlicense](https://choosealicense.com/licenses/unlicense/) License. See [UNLICENSE](https://github.com/Ravencentric/archivefile/blob/main/UNLICENSE) for more information.\n",
    "bugtrack_url": null,
    "license": "Unlicense",
    "summary": "Unified interface for tar, zip, sevenzip, and rar files",
    "version": "0.3.1",
    "project_urls": {
        "Documentation": "https://ravencentric.github.io/archivefile",
        "Homepage": "https://ravencentric.github.io/archivefile",
        "Repository": "https://github.com/Ravencentric/archivefile"
    },
    "split_keywords": [
        "archive",
        " archivefile",
        " zipfile",
        " tarfile",
        " sevenzip",
        " rarfile"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "111781b8dac7c375f45f6549b17224eca39360a86e2f2b932588162d5c6176f5",
                "md5": "094a8f544bc5a631cc65761efe012c09",
                "sha256": "6a5cfa82be31081fbbbfea4d7d80ce03a96096940fb98e96f3abcce2eec4da8e"
            },
            "downloads": -1,
            "filename": "archivefile-0.3.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "094a8f544bc5a631cc65761efe012c09",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 14500,
            "upload_time": "2024-05-11T19:07:30",
            "upload_time_iso_8601": "2024-05-11T19:07:30.324552Z",
            "url": "https://files.pythonhosted.org/packages/11/17/81b8dac7c375f45f6549b17224eca39360a86e2f2b932588162d5c6176f5/archivefile-0.3.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "9a9ce6537b367daee3b1bcf64de162a1b28049d38b1eb005b142b904214b482e",
                "md5": "808c8894b6226dff5b28cb2e45fc2401",
                "sha256": "ed50af297bb669c5c662e7c7fd42d9dc353f2c1f7e4d34e64b2ff162f4438da8"
            },
            "downloads": -1,
            "filename": "archivefile-0.3.1.tar.gz",
            "has_sig": false,
            "md5_digest": "808c8894b6226dff5b28cb2e45fc2401",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 14209,
            "upload_time": "2024-05-11T19:07:31",
            "upload_time_iso_8601": "2024-05-11T19:07:31.919236Z",
            "url": "https://files.pythonhosted.org/packages/9a/9c/e6537b367daee3b1bcf64de162a1b28049d38b1eb005b142b904214b482e/archivefile-0.3.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-05-11 19:07:31",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "Ravencentric",
    "github_project": "archivefile",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "archivefile"
}
        
Elapsed time: 0.25999s