pathlib-mate


Namepathlib-mate JSON
Version 1.3.2 PyPI version JSON
download
home_pagehttps://github.com/MacHu-GWU/pathlib_mate-project
SummaryAn extended and more powerful pathlib.
upload_time2024-01-22 03:19:16
maintainerSanhe Hu
docs_urlNone
authorSanhe Hu
requires_python>=3.7
licenseMIT
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI
coveralls test coverage
            .. image:: https://readthedocs.org/projects/pathlib_mate/badge/?version=latest
    :target: https://pathlib-mate.readthedocs.io/?badge=latest
    :alt: Documentation Status

.. image:: https://github.com/MacHu-GWU/pathlib_mate-project/workflows/CI/badge.svg
    :target: https://github.com/MacHu-GWU/pathlib_mate-project/actions?query=workflow:CI

.. image:: https://codecov.io/gh/MacHu-GWU/pathlib_mate-project/branch/master/graph/badge.svg
  :target: https://codecov.io/gh/MacHu-GWU/pathlib_mate-project

.. image:: https://img.shields.io/pypi/v/pathlib_mate.svg
    :target: https://pypi.python.org/pypi/pathlib_mate

.. image:: https://img.shields.io/pypi/l/pathlib_mate.svg
    :target: https://pypi.python.org/pypi/pathlib_mate

.. image:: https://img.shields.io/pypi/pyversions/pathlib_mate.svg
    :target: https://pypi.python.org/pypi/pathlib_mate

.. image:: https://img.shields.io/pypi/dm/pathlib_mate.svg
    :target: https://github.com/MacHu-GWU/pathlib_mate-project

.. image:: https://img.shields.io/badge/Release_History!--None.svg?style=social
    :target: https://github.com/MacHu-GWU/pathlib_mate-project/blob/master/release-history.rst

.. image:: https://img.shields.io/badge/STAR_Me_on_GitHub!--None.svg?style=social
    :target: https://github.com/MacHu-GWU/pathlib_mate-project


------


.. image:: https://img.shields.io/badge/Link-Document-blue.svg
      :target: https://pathlib-mate.readthedocs.io/index.html

.. image:: https://img.shields.io/badge/Link-API-blue.svg
      :target: https://pathlib-mate.readthedocs.io/py-modindex.html

.. image:: https://img.shields.io/badge/Link-Source_Code-blue.svg
      :target: https://pathlib-mate.readthedocs.io/py-modindex.html

.. image:: https://img.shields.io/badge/Link-Install-blue.svg
      :target: `install`_

.. image:: https://img.shields.io/badge/Link-GitHub-blue.svg
      :target: https://github.com/MacHu-GWU/pathlib_mate-project

.. image:: https://img.shields.io/badge/Link-Submit_Issue-blue.svg
      :target: https://github.com/MacHu-GWU/pathlib_mate-project/issues

.. image:: https://img.shields.io/badge/Link-Request_Feature-blue.svg
      :target: https://github.com/MacHu-GWU/pathlib_mate-project/issues

.. image:: https://img.shields.io/badge/Link-Download-blue.svg
      :target: https://pypi.org/pypi/pathlib_mate#files


Welcome to ``pathlib_mate`` Documentation
==============================================================================

`pathlib <https://docs.python.org/3/library/pathlib.html>`_ is an awesome library handling path in different OS. And it's been added into standard library since Python3.4. ``pathlib_mate`` gives extensive methods and attributes, makes ``pathlib`` more powerful and user-friendly.

Features:

**Convenient Attribute Accessor**:

.. code-block:: python

    >>> p = Path("/Users/username/test.py").

    >>> p.abspath
    /Users/username/test.py

    >>> p.basename
    test.py

    >>> p.fname
    test

    >>> p.ext
    .py

    >>> p.dirname
    username

    >>> p.dirpath
    /Users/username

    >>> p.size
    1500

    >>> p.size_in_text
    1.46 KB

    >>> p.create_datetime
    datetime(2018, 1, 15, 8, 30, 15)

    >>> p.md5
    415f12f07a7e01486cc82856621e05bf

    >>> p.sha256
    d51512cb0ac71484c01c475409a73225d0149165024d7aac6d8e655eedf2c025

    >>> p.sha512
    7882fc375840cafa364eaf29dc424645b72fcdbe61fc3326c5afd98e70f696e4f390e0e3f159eac2cb60cedc0992ef7b5f8744a4481911e914a7c5b979e6de68

**Powerful Path Search**:

.. code-block:: python

    >>> p = Path("/Users/username/Documents")

    >>> for path in p.select_file(recursive=True)
    ...

    >>> for path in p.select_file(recursive=False)
    ...

    >>> for path in p.select_dir(recursive=True)
    ...

    >>> for image_file in p.select_by_ext([".jpg", ".png"])
    ...

    >>> for big_file in p.select_by_size(min_size=1000000)
    ...

    >>> for video_file in p.select_video():
    ...

    # You can customize the filter anyway you want
    >>> def py_filter(p): return ".py" == p.ext.lower()
    >>> for py_file in p.select_file(py_filter):
    ...


**Eazy to use File / Dir Operation**:

.. code-block:: python

    >>> p = Path("/Users/username/Documents/Readme.txt")

    # mutate
    >>> p.change(new_ext=".md")
    /Users/username/Documents/Readme.md

    >>> p.change(new_fname="Tutorial")
    /Users/username/Documents/Tutorial.txt

    >>> p.change(new_basename="README.rst")
    /Users/username/Documents/README.rst

    >>> p.change(new_dirname="Downloads")
    /Users/username/Downloads/Readme.txt

    >>> p.change(new_dirpath="/User/username/Downloads)
    /Users/username/Downloads/Readme.txt

    >>> p.change(new_abspath="/Users/username/Downloads/Readme.txt")
    /Users/username/Downloads/Readme.txt

    # copy
    >>> p.moveto(new_ext=".md", makedirs=True)

    # cut
    >>> p.copyto(new_ext=".md", makedirs=True)

    # delete
    >>> p.remove()

    # delete file or directory recursively, ignore if not exists
    >>> p.remove_if_exists()

    # make dir and required parents recursively, if not exists
    >>> p.mkdir_if_not_exists()


**Atomic Write Support**:

If anything wrong happens during writing big chunk of data into a file. It may leave you an incomplete file. Atomic write can guarantee either 100% done or nothing happens.

Thanks for `boltons <https://boltons.readthedocs.io/en/latest/>`_ project. Now ``pathlib_mate`` supports atomic write API:

.. code-block:: python

    >>> p = Path("test.dat")
    >>> s = "Hello World"
    >>> b = s.encode("utf-8)
    >>> p.atomic_write_bytes(b, overwrite=True)
    >>> p.atomic_write_text(s, overwrite=True)
    >>> with p.atomic_open("wb") as f:
    ...     f.write(b) # write large binary data


**Powerful Production Tools**:

.. code-block:: python

    >>> p = Path("/Users/username/Documents/Github/pathlib_mate-project")

    >>> p.print_big_dir_and_big_file()
    ...

    >>> p.file_stat()
    {"file": 122, "dir": 41, "size": 619682}

    # file statistics, include sub folder
    >>> p.file_stat_for_all()

    # make an zip archive for the directory, auto naming
    >>> p.make_zip_archive()

    # make an zip archive for the directory, auto naming
    >>> p.backup()


.. _install:

Install
------------------------------------------------------------------------------

``pathlib_mate`` is released on PyPI, so all you need is:

.. code-block:: console

    $ pip install pathlib_mate

To upgrade to latest version:

.. code-block:: console

    $ pip install --upgrade pathlib_mate

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/MacHu-GWU/pathlib_mate-project",
    "name": "pathlib-mate",
    "maintainer": "Sanhe Hu",
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": "husanhe@gmail.com",
    "keywords": "",
    "author": "Sanhe Hu",
    "author_email": "husanhe@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/ff/dd/ee187b2d46bced8deb3b69ebfdb07c74cc622d5ddc1bec208cdc76b23b3a/pathlib_mate-1.3.2.tar.gz",
    "platform": "Windows",
    "description": ".. image:: https://readthedocs.org/projects/pathlib_mate/badge/?version=latest\n    :target: https://pathlib-mate.readthedocs.io/?badge=latest\n    :alt: Documentation Status\n\n.. image:: https://github.com/MacHu-GWU/pathlib_mate-project/workflows/CI/badge.svg\n    :target: https://github.com/MacHu-GWU/pathlib_mate-project/actions?query=workflow:CI\n\n.. image:: https://codecov.io/gh/MacHu-GWU/pathlib_mate-project/branch/master/graph/badge.svg\n  :target: https://codecov.io/gh/MacHu-GWU/pathlib_mate-project\n\n.. image:: https://img.shields.io/pypi/v/pathlib_mate.svg\n    :target: https://pypi.python.org/pypi/pathlib_mate\n\n.. image:: https://img.shields.io/pypi/l/pathlib_mate.svg\n    :target: https://pypi.python.org/pypi/pathlib_mate\n\n.. image:: https://img.shields.io/pypi/pyversions/pathlib_mate.svg\n    :target: https://pypi.python.org/pypi/pathlib_mate\n\n.. image:: https://img.shields.io/pypi/dm/pathlib_mate.svg\n    :target: https://github.com/MacHu-GWU/pathlib_mate-project\n\n.. image:: https://img.shields.io/badge/Release_History!--None.svg?style=social\n    :target: https://github.com/MacHu-GWU/pathlib_mate-project/blob/master/release-history.rst\n\n.. image:: https://img.shields.io/badge/STAR_Me_on_GitHub!--None.svg?style=social\n    :target: https://github.com/MacHu-GWU/pathlib_mate-project\n\n\n------\n\n\n.. image:: https://img.shields.io/badge/Link-Document-blue.svg\n      :target: https://pathlib-mate.readthedocs.io/index.html\n\n.. image:: https://img.shields.io/badge/Link-API-blue.svg\n      :target: https://pathlib-mate.readthedocs.io/py-modindex.html\n\n.. image:: https://img.shields.io/badge/Link-Source_Code-blue.svg\n      :target: https://pathlib-mate.readthedocs.io/py-modindex.html\n\n.. image:: https://img.shields.io/badge/Link-Install-blue.svg\n      :target: `install`_\n\n.. image:: https://img.shields.io/badge/Link-GitHub-blue.svg\n      :target: https://github.com/MacHu-GWU/pathlib_mate-project\n\n.. image:: https://img.shields.io/badge/Link-Submit_Issue-blue.svg\n      :target: https://github.com/MacHu-GWU/pathlib_mate-project/issues\n\n.. image:: https://img.shields.io/badge/Link-Request_Feature-blue.svg\n      :target: https://github.com/MacHu-GWU/pathlib_mate-project/issues\n\n.. image:: https://img.shields.io/badge/Link-Download-blue.svg\n      :target: https://pypi.org/pypi/pathlib_mate#files\n\n\nWelcome to ``pathlib_mate`` Documentation\n==============================================================================\n\n`pathlib <https://docs.python.org/3/library/pathlib.html>`_ is an awesome library handling path in different OS. And it's been added into standard library since Python3.4. ``pathlib_mate`` gives extensive methods and attributes, makes ``pathlib`` more powerful and user-friendly.\n\nFeatures:\n\n**Convenient Attribute Accessor**:\n\n.. code-block:: python\n\n    >>> p = Path(\"/Users/username/test.py\").\n\n    >>> p.abspath\n    /Users/username/test.py\n\n    >>> p.basename\n    test.py\n\n    >>> p.fname\n    test\n\n    >>> p.ext\n    .py\n\n    >>> p.dirname\n    username\n\n    >>> p.dirpath\n    /Users/username\n\n    >>> p.size\n    1500\n\n    >>> p.size_in_text\n    1.46 KB\n\n    >>> p.create_datetime\n    datetime(2018, 1, 15, 8, 30, 15)\n\n    >>> p.md5\n    415f12f07a7e01486cc82856621e05bf\n\n    >>> p.sha256\n    d51512cb0ac71484c01c475409a73225d0149165024d7aac6d8e655eedf2c025\n\n    >>> p.sha512\n    7882fc375840cafa364eaf29dc424645b72fcdbe61fc3326c5afd98e70f696e4f390e0e3f159eac2cb60cedc0992ef7b5f8744a4481911e914a7c5b979e6de68\n\n**Powerful Path Search**:\n\n.. code-block:: python\n\n    >>> p = Path(\"/Users/username/Documents\")\n\n    >>> for path in p.select_file(recursive=True)\n    ...\n\n    >>> for path in p.select_file(recursive=False)\n    ...\n\n    >>> for path in p.select_dir(recursive=True)\n    ...\n\n    >>> for image_file in p.select_by_ext([\".jpg\", \".png\"])\n    ...\n\n    >>> for big_file in p.select_by_size(min_size=1000000)\n    ...\n\n    >>> for video_file in p.select_video():\n    ...\n\n    # You can customize the filter anyway you want\n    >>> def py_filter(p): return \".py\" == p.ext.lower()\n    >>> for py_file in p.select_file(py_filter):\n    ...\n\n\n**Eazy to use File / Dir Operation**:\n\n.. code-block:: python\n\n    >>> p = Path(\"/Users/username/Documents/Readme.txt\")\n\n    # mutate\n    >>> p.change(new_ext=\".md\")\n    /Users/username/Documents/Readme.md\n\n    >>> p.change(new_fname=\"Tutorial\")\n    /Users/username/Documents/Tutorial.txt\n\n    >>> p.change(new_basename=\"README.rst\")\n    /Users/username/Documents/README.rst\n\n    >>> p.change(new_dirname=\"Downloads\")\n    /Users/username/Downloads/Readme.txt\n\n    >>> p.change(new_dirpath=\"/User/username/Downloads)\n    /Users/username/Downloads/Readme.txt\n\n    >>> p.change(new_abspath=\"/Users/username/Downloads/Readme.txt\")\n    /Users/username/Downloads/Readme.txt\n\n    # copy\n    >>> p.moveto(new_ext=\".md\", makedirs=True)\n\n    # cut\n    >>> p.copyto(new_ext=\".md\", makedirs=True)\n\n    # delete\n    >>> p.remove()\n\n    # delete file or directory recursively, ignore if not exists\n    >>> p.remove_if_exists()\n\n    # make dir and required parents recursively, if not exists\n    >>> p.mkdir_if_not_exists()\n\n\n**Atomic Write Support**:\n\nIf anything wrong happens during writing big chunk of data into a file. It may leave you an incomplete file. Atomic write can guarantee either 100% done or nothing happens.\n\nThanks for `boltons <https://boltons.readthedocs.io/en/latest/>`_ project. Now ``pathlib_mate`` supports atomic write API:\n\n.. code-block:: python\n\n    >>> p = Path(\"test.dat\")\n    >>> s = \"Hello World\"\n    >>> b = s.encode(\"utf-8)\n    >>> p.atomic_write_bytes(b, overwrite=True)\n    >>> p.atomic_write_text(s, overwrite=True)\n    >>> with p.atomic_open(\"wb\") as f:\n    ...     f.write(b) # write large binary data\n\n\n**Powerful Production Tools**:\n\n.. code-block:: python\n\n    >>> p = Path(\"/Users/username/Documents/Github/pathlib_mate-project\")\n\n    >>> p.print_big_dir_and_big_file()\n    ...\n\n    >>> p.file_stat()\n    {\"file\": 122, \"dir\": 41, \"size\": 619682}\n\n    # file statistics, include sub folder\n    >>> p.file_stat_for_all()\n\n    # make an zip archive for the directory, auto naming\n    >>> p.make_zip_archive()\n\n    # make an zip archive for the directory, auto naming\n    >>> p.backup()\n\n\n.. _install:\n\nInstall\n------------------------------------------------------------------------------\n\n``pathlib_mate`` is released on PyPI, so all you need is:\n\n.. code-block:: console\n\n    $ pip install pathlib_mate\n\nTo upgrade to latest version:\n\n.. code-block:: console\n\n    $ pip install --upgrade pathlib_mate\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "An extended and more powerful pathlib.",
    "version": "1.3.2",
    "project_urls": {
        "Download": "https://pypi.python.org/pypi/pathlib_mate/1.3.2#downloads",
        "Homepage": "https://github.com/MacHu-GWU/pathlib_mate-project"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "5e0f6b6342767cb06562f4d67295191cd5c63775c04765766499a70265388db6",
                "md5": "c37fd0c52ee6d8ca9a4d73ab0fffdb4b",
                "sha256": "a4b29e0d38abb14e25a8a292856a04c7f48b2eafe9f7ebf36166dec5a13a0b0d"
            },
            "downloads": -1,
            "filename": "pathlib_mate-1.3.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "c37fd0c52ee6d8ca9a4d73ab0fffdb4b",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 56988,
            "upload_time": "2024-01-22T03:19:14",
            "upload_time_iso_8601": "2024-01-22T03:19:14.192085Z",
            "url": "https://files.pythonhosted.org/packages/5e/0f/6b6342767cb06562f4d67295191cd5c63775c04765766499a70265388db6/pathlib_mate-1.3.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "ffddee187b2d46bced8deb3b69ebfdb07c74cc622d5ddc1bec208cdc76b23b3a",
                "md5": "4108914c82ca4dbf4d71da6785f3beca",
                "sha256": "8e16efd03016d4dd2ff0dc5dc05db666bebea6c8528aebd471953287644dd3e6"
            },
            "downloads": -1,
            "filename": "pathlib_mate-1.3.2.tar.gz",
            "has_sig": false,
            "md5_digest": "4108914c82ca4dbf4d71da6785f3beca",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 61942,
            "upload_time": "2024-01-22T03:19:16",
            "upload_time_iso_8601": "2024-01-22T03:19:16.188697Z",
            "url": "https://files.pythonhosted.org/packages/ff/dd/ee187b2d46bced8deb3b69ebfdb07c74cc622d5ddc1bec208cdc76b23b3a/pathlib_mate-1.3.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-01-22 03:19:16",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "MacHu-GWU",
    "github_project": "pathlib_mate-project",
    "travis_ci": true,
    "coveralls": true,
    "github_actions": true,
    "requirements": [],
    "tox": true,
    "lcname": "pathlib-mate"
}
        
Elapsed time: 0.72690s