# 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)
```
## Delete a folder
```python
# Create an pathlibs3 object
s3_path_to_myfolder = S3Path(client, bucket, "myfolder/")
s3_path_to_myfolder.delete()
```
## Move a folder
```python
# Create an pathlibs3 object
s3_path_to_myfolder = S3Path(client, bucket, "myfolder/")
s3_path_other_folder = S3Path(client, bucket, "myotherfolder/")
S3Path.move(s3_path_to_myfolder, s3_path_other_folder)
```
# 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/2f/d6/53a18b5ff17d2ef50cd09ba0f931306ecbae0ddc1ddd696cdc8cad2a1de5/pathlibs3-1.1.7.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## Delete a folder\n```python\n# Create an pathlibs3 object\ns3_path_to_myfolder = S3Path(client, bucket, \"myfolder/\")\ns3_path_to_myfolder.delete()\n```\n\n## Move a folder\n```python\n# Create an pathlibs3 object\ns3_path_to_myfolder = S3Path(client, bucket, \"myfolder/\")\ns3_path_other_folder = S3Path(client, bucket, \"myotherfolder/\")\nS3Path.move(s3_path_to_myfolder, s3_path_other_folder)\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.1.7",
"project_urls": {
"Homepage": "https://github.com/thibaultbl/s3_navigator"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "196e267d122ddccd361d61fef23d935a04acb70e834dc37308111553d1466340",
"md5": "a2bd3162bc235f6de04591936f9e8c0e",
"sha256": "9956f4584a09b9410d3a6aab13dee03f8de9ebce86d27f91a0b8f2ea5f24ba60"
},
"downloads": -1,
"filename": "pathlibs3-1.1.7-py3-none-any.whl",
"has_sig": false,
"md5_digest": "a2bd3162bc235f6de04591936f9e8c0e",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.10",
"size": 4001,
"upload_time": "2024-07-18T14:19:32",
"upload_time_iso_8601": "2024-07-18T14:19:32.779337Z",
"url": "https://files.pythonhosted.org/packages/19/6e/267d122ddccd361d61fef23d935a04acb70e834dc37308111553d1466340/pathlibs3-1.1.7-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "2fd653a18b5ff17d2ef50cd09ba0f931306ecbae0ddc1ddd696cdc8cad2a1de5",
"md5": "7c6b6239b16a458d76ef8e24f2fdd434",
"sha256": "0404d2ffabf2773e10c03eba41c5763e4e05387dcd249de02c6a1378a839baef"
},
"downloads": -1,
"filename": "pathlibs3-1.1.7.tar.gz",
"has_sig": false,
"md5_digest": "7c6b6239b16a458d76ef8e24f2fdd434",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.10",
"size": 3603,
"upload_time": "2024-07-18T14:19:34",
"upload_time_iso_8601": "2024-07-18T14:19:34.915234Z",
"url": "https://files.pythonhosted.org/packages/2f/d6/53a18b5ff17d2ef50cd09ba0f931306ecbae0ddc1ddd696cdc8cad2a1de5/pathlibs3-1.1.7.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-07-18 14:19:34",
"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"
}