Skip to main content

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_ID
  • AWS_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, or null if the file could not be read.
  • content_size_mb: A float representing the size of the content in megabytes, or null if the file could not be read.
  • binary: A boolean indicating whether the file is binary (true) or text (false), or null if the file could not be read.
  • debug: An object containing debug information, or null if 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, or null if the file could not be written.
  • content_size_mb: A float representing the size of the content in megabytes, or null if the file could not be written.
  • binary: A boolean indicating whether the file is binary (true) or text (false), or null if the file could not be written.
  • debug: An object containing debug information, or null if 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, or null if 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

klingon_file_manager-0.0.33.tar.gz (9.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

klingon_file_manager-0.0.33-py3-none-any.whl (9.3 kB view details)

Uploaded Python 3

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

Hashes for klingon_file_manager-0.0.33.tar.gz
Algorithm Hash digest
SHA256 8eddbc580c5e9c18eae9f33552b3f93ab87cce207352a1b69f909560010cee18
MD5 9ff51465be708404caf7e1d4727d74a4
BLAKE2b-256 6868e10b48c1cc07baea8d385d6395b8dee2644cf8faa29200620acce0a542e5

See more details on using hashes here.

File details

Details for the file klingon_file_manager-0.0.33-py3-none-any.whl.

File metadata

File hashes

Hashes for klingon_file_manager-0.0.33-py3-none-any.whl
Algorithm Hash digest
SHA256 b45e04ed012c967c4efe1ef94e36011d7a52f39bb668443fb7c24b04a0310aad
MD5 fc1a583261c00b71331a30e39b371897
BLAKE2b-256 7ad0531db4d7f781bc2fb8f3114475576945e4595129c50cee26b268a2492963

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page