A Python module for managing files on both local and AWS S3 storage.
Project description
Klingon File Manager
Introduction
The Klingon File Manager is a Python module designed for managing files both locally and on AWS S3 storage. It provides functionalities to 'get' and 'post' files using a unified interface.
Installation
Run the following command to install the package:
pip install klingon-file-manager
The module looks for the following environment variables:
AWS_ACCESS_KEY_IDAWS_SECRET_ACCESS_KEY
Features
- Supports both local and AWS S3 storage
- Single function interface (
manage_file) to handle 'get' and 'post' operations - Debugging support
Usage Examples
Using manage_file function
Here's a basic example to get you started:
GET example
GET is the same as reading/downloading a file either locally or on S3.
from klingon_file_manager import manage_file
result = manage_file(action='get', path='path/to/local/file.txt')
print(result)
When the 'get' action is used with the manage_file function, the output is a dictionary (which can be converted to a JSON object) with the following schema:
{
"status": "integer",
"action": "string",
"path": "string",
"content": "string or bytes or null",
"content_size_mb": "float or null",
"binary": "boolean or null",
"debug": "object or null"
}
Here is a description of each field:
status: An integer representing the status of the operation. A status of 200 indicates success, while a status of 500 indicates an error.action: A string representing the action performed. In this case, it will be 'get'.path: A string representing the path of the file that was read.content: A string or bytes representing the content of the file that was read, ornullif the file could not be read.content_size_mb: A float representing the size of the content in megabytes, ornullif the file could not be read.binary: A boolean indicating whether the file is binary (true) or text (false), ornullif the file could not be read.debug: An object containing debug information, ornullif debugging is not enabled.
POST example
POST is the same as saving/uploading a file either locally or on S3.
from klingon_file_manager import manage_file
# POST a file to S3
result = manage_file(action='post', path='s3://your-bucket/your-key', content='Your content here')
print(result)
When the 'post' action is used with the manage_file function, the output is a dictionary (which can be converted to a JSON object) with the following schema:
{
"status": "integer",
"action": "string",
"path": "string",
"content": "string or bytes or null",
"content_size_mb": "float or null",
"binary": "boolean or null",
"debug": "object or null"
}
Here is a description of each field:
status: An integer representing the status of the operation. A status of 200 indicates success, while a status of 500 indicates an error.action: A string representing the action performed. In this case, it will be 'post'.path: A string representing the path of the file that was written.content: A string or bytes representing the content that was written to the file, ornullif the file could not be written.content_size_mb: A float representing the size of the content in megabytes, ornullif the file could not be written.binary: A boolean indicating whether the file is binary (true) or text (false), ornullif the file could not be written.debug: An object containing debug information, ornullif debugging is not enabled.
DELETE example
DELETE allows you to delete files either locally or stored on S3.
from klingon_file_manager import manage_file
# To delete a file from local storage
result = manage_file(action='delete', path='path/to/local/file.txt')
print(result)
When the 'delete' action is used with the manage_file function, the output is a dictionary (which can be converted to a JSON object) with the following schema:
{
"status": "integer",
"action": "string",
"path": "string",
"debug": "object or null"
}
Here is a description of each field:
status: An integer representing the status of the operation. A status of 200 indicates success, while a status of 500 indicates an error.action: A string representing the action performed. In this case, it will be 'delete'.path: A string representing the path of the file that was deleted.debug: An object containing debug information, ornullif debugging is not enabled.
Contribution Guidelines
If you wish to contribute to this project, please submit a pull request.
Running Tests
To run tests, execute the following command:
pytest
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file klingon_file_manager-0.0.33.tar.gz.
File metadata
- Download URL: klingon_file_manager-0.0.33.tar.gz
- Upload date:
- Size: 9.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.12.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8eddbc580c5e9c18eae9f33552b3f93ab87cce207352a1b69f909560010cee18
|
|
| MD5 |
9ff51465be708404caf7e1d4727d74a4
|
|
| BLAKE2b-256 |
6868e10b48c1cc07baea8d385d6395b8dee2644cf8faa29200620acce0a542e5
|
File details
Details for the file klingon_file_manager-0.0.33-py3-none-any.whl.
File metadata
- Download URL: klingon_file_manager-0.0.33-py3-none-any.whl
- Upload date:
- Size: 9.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.12.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b45e04ed012c967c4efe1ef94e36011d7a52f39bb668443fb7c24b04a0310aad
|
|
| MD5 |
fc1a583261c00b71331a30e39b371897
|
|
| BLAKE2b-256 |
7ad0531db4d7f781bc2fb8f3114475576945e4595129c50cee26b268a2492963
|