pathlibs3


Namepathlibs3 JSON
Version 1.0.0 PyPI version JSON
download
home_pagehttps://github.com/thibaultbl/s3_navigator
SummaryS3 navigation using object, inspired by pathlib.Path
upload_time2024-06-16 09:19:12
maintainerNone
docs_urlNone
authorthibault.blanc
requires_python>=3.10
licenseApache-2.0
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Installation

```sh
pip install pathlibs3
```

# Usage

## Create a PathlibS3 Object
```python
from pathlibs3.pathlibs3 import S3Path
# Create a pathlibs3

client = boto3.client("s3", region_name="us-east-1")
bucket = "test-bucket"

# Create an object to s3://test-bucket/myfolder
s3_path_to_myfolder = S3Path(client, bucket, "myfolder/")


# You can also concatenate object
# Create an object to s3://test-bucket/myfile/random_file.txt
s3_path_to_random_file = s3_path_to_myfolder / "random_file.txt"
```

## Iter over a directory

```Python
# Iter over this directory
for path in s3_path.iterdir():
    print(path)

# Iter over this directory recursively
for path in s3_path.iterdir(recursive=True):
    print(path)
```

## Use classic pathlib.Path function

### parent and parents
```Python
>> s3_path_to_myfolder = S3Path(client, bucket, "myfolder/folder1/folder2")
>> s3_path_to_myfolder.parent

S3Path(client, bucket, "myfolder/folder1")

>> s3_path_to_myfolder.parents
[S3Path(client, bucket, "myfolder/folder1"), S3Path(client, bucket, "myfolder")]

```
### name

```Python
>> s3_path_to_myfolder = S3Path(client, bucket, "myfolder/folder1/folder2/test.txt")
>> s3_path_to_myfolder.name
"test.txt"
```

### exists
```Python
>> s3_path_to_myfolder = S3Path(client, bucket, "myfolder/folder1/folder2/test.txt")
>> s3_path_to_myfolder.exists()
True
```

## Copy file or folder

### Copy from s3 to local
```python
# Create an pathlibs3 object
s3_path_to_myfolder = S3Path(client, bucket, "myfolder/")

# Create a pathlib object
local_path = Path("/tmp/local_folder")

# Will download the s3 folder localy
S3Path.copy(s3_path_to_myfolder, local_path)

# You may also use string for local path
# Example: copy from s3 to local dir using string
S3Path.copy(s3_path_to_myfolder, "/tmp/local_folder")
```

### Copy from local to s3
```python
# Create an pathlibs3 object
s3_path_to_myfolder = S3Path(client, bucket, "myfolder/")

# Create a pathlib object
local_path = Path("/tmp/local_folder")

# Will download the s3 folder localy
S3Path.copy(local_path, s3_path_to_myfolder)

```


### Copy from s3 to s3
```python
# Create an pathlibs3 object
s3_path_to_myfolder = S3Path(client, bucket, "myfolder/")

# Create another pathlibs3 object
s3_path_to_anotherfolder = S3Path(client, bucket, "anotherfolder/")

# Will download the s3 folder localy
S3Path.copy(s3_path_to_myfolder, s3_path_to_anotherfolder)

```


# Contribution
## run test

run test with `poetry run python -m pytest`

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/thibaultbl/s3_navigator",
    "name": "pathlibs3",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.10",
    "maintainer_email": null,
    "keywords": null,
    "author": "thibault.blanc",
    "author_email": null,
    "download_url": "https://files.pythonhosted.org/packages/d1/f0/246cbcdbf6209a27620a143573d563c4f5f53b13131bb01968694ef3f5ad/pathlibs3-1.0.0.tar.gz",
    "platform": null,
    "description": "# Installation\n\n```sh\npip install pathlibs3\n```\n\n# Usage\n\n## Create a PathlibS3 Object\n```python\nfrom pathlibs3.pathlibs3 import S3Path\n# Create a pathlibs3\n\nclient = boto3.client(\"s3\", region_name=\"us-east-1\")\nbucket = \"test-bucket\"\n\n# Create an object to s3://test-bucket/myfolder\ns3_path_to_myfolder = S3Path(client, bucket, \"myfolder/\")\n\n\n# You can also concatenate object\n# Create an object to s3://test-bucket/myfile/random_file.txt\ns3_path_to_random_file = s3_path_to_myfolder / \"random_file.txt\"\n```\n\n## Iter over a directory\n\n```Python\n# Iter over this directory\nfor path in s3_path.iterdir():\n    print(path)\n\n# Iter over this directory recursively\nfor path in s3_path.iterdir(recursive=True):\n    print(path)\n```\n\n## Use classic pathlib.Path function\n\n### parent and parents\n```Python\n>> s3_path_to_myfolder = S3Path(client, bucket, \"myfolder/folder1/folder2\")\n>> s3_path_to_myfolder.parent\n\nS3Path(client, bucket, \"myfolder/folder1\")\n\n>> s3_path_to_myfolder.parents\n[S3Path(client, bucket, \"myfolder/folder1\"), S3Path(client, bucket, \"myfolder\")]\n\n```\n### name\n\n```Python\n>> s3_path_to_myfolder = S3Path(client, bucket, \"myfolder/folder1/folder2/test.txt\")\n>> s3_path_to_myfolder.name\n\"test.txt\"\n```\n\n### exists\n```Python\n>> s3_path_to_myfolder = S3Path(client, bucket, \"myfolder/folder1/folder2/test.txt\")\n>> s3_path_to_myfolder.exists()\nTrue\n```\n\n## Copy file or folder\n\n### Copy from s3 to local\n```python\n# Create an pathlibs3 object\ns3_path_to_myfolder = S3Path(client, bucket, \"myfolder/\")\n\n# Create a pathlib object\nlocal_path = Path(\"/tmp/local_folder\")\n\n# Will download the s3 folder localy\nS3Path.copy(s3_path_to_myfolder, local_path)\n\n# You may also use string for local path\n# Example: copy from s3 to local dir using string\nS3Path.copy(s3_path_to_myfolder, \"/tmp/local_folder\")\n```\n\n### Copy from local to s3\n```python\n# Create an pathlibs3 object\ns3_path_to_myfolder = S3Path(client, bucket, \"myfolder/\")\n\n# Create a pathlib object\nlocal_path = Path(\"/tmp/local_folder\")\n\n# Will download the s3 folder localy\nS3Path.copy(local_path, s3_path_to_myfolder)\n\n```\n\n\n### Copy from s3 to s3\n```python\n# Create an pathlibs3 object\ns3_path_to_myfolder = S3Path(client, bucket, \"myfolder/\")\n\n# Create another pathlibs3 object\ns3_path_to_anotherfolder = S3Path(client, bucket, \"anotherfolder/\")\n\n# Will download the s3 folder localy\nS3Path.copy(s3_path_to_myfolder, s3_path_to_anotherfolder)\n\n```\n\n\n# Contribution\n## run test\n\nrun test with `poetry run python -m pytest`\n",
    "bugtrack_url": null,
    "license": "Apache-2.0",
    "summary": "S3 navigation using object, inspired by pathlib.Path",
    "version": "1.0.0",
    "project_urls": {
        "Homepage": "https://github.com/thibaultbl/s3_navigator"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "5ca89e70ab6dbdeba988dbc8d43bdd014c71a6d5643fc0bb27b6c91b37ff637c",
                "md5": "87d0512cf4e636769d8d6332ddde543a",
                "sha256": "b3e8411840906edbe0f0bb096c438477e941a530005e1f15cfbe2b1da288b5a3"
            },
            "downloads": -1,
            "filename": "pathlibs3-1.0.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "87d0512cf4e636769d8d6332ddde543a",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10",
            "size": 3418,
            "upload_time": "2024-06-16T09:19:11",
            "upload_time_iso_8601": "2024-06-16T09:19:11.289888Z",
            "url": "https://files.pythonhosted.org/packages/5c/a8/9e70ab6dbdeba988dbc8d43bdd014c71a6d5643fc0bb27b6c91b37ff637c/pathlibs3-1.0.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "d1f0246cbcdbf6209a27620a143573d563c4f5f53b13131bb01968694ef3f5ad",
                "md5": "605fdc7b0e9064a5cf37468b1ef11d85",
                "sha256": "91e9fcf47f5364c1ced6d0429bc512948eafa3da0f710fe79529c63f3511e146"
            },
            "downloads": -1,
            "filename": "pathlibs3-1.0.0.tar.gz",
            "has_sig": false,
            "md5_digest": "605fdc7b0e9064a5cf37468b1ef11d85",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10",
            "size": 3633,
            "upload_time": "2024-06-16T09:19:12",
            "upload_time_iso_8601": "2024-06-16T09:19:12.537517Z",
            "url": "https://files.pythonhosted.org/packages/d1/f0/246cbcdbf6209a27620a143573d563c4f5f53b13131bb01968694ef3f5ad/pathlibs3-1.0.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-06-16 09:19:12",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "thibaultbl",
    "github_project": "s3_navigator",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "pathlibs3"
}
        
Elapsed time: 0.42051s