Library that facilitates file and folder manipulation in Python.
Project description
pathpilot
pathpilot
is a Python package that makes file and folder manipulation simple and intuitive. It was designed with an emphasis on pandas
compatibility to ensure smooth workflows.
Installation
pip install pathpilot
Main Features
File
➔ Function that assigns new file instances to the correct child class. Many file types are supported natively including: .xlsx, .csv, .txt, .pickle, etc. The mapping of file extensions to their respective classes is managed using theextension_mapping
global dictionary. Unmapped extensions are assigned to theFileBase
class.Folder
➔ Class for interacting with folders. It is important to be mindful of theread_only
parameter which, if set toTrue
, allows folders to be created or deleted programically.
Example Usage
Please note the examples below represent a small fraction of the functionality offered by pathpilot
. Please refer to the documentation within the code for more information.
Imports
from pathpilot import Folder, File
Folders
First, we create an instance of the Folder
class. Passing read_only=False
causes the folder to be created if it does not already exist.
# initiate a folder instance
folder = Folder(r'C:\Users\MyID\Documents\MyFolder', read_only=False)
Moreover, any subfolders that are referenced while interacting with the folder instance will also be created automatically. Let's use the join
method to create a couple subfolders.
# create subfolders (i.e. C:\Users\MyID\Documents\MyFolder\Year\2025\Month\)
month_folder = folder.join('Year', '2025', 'Month')
Alternatively, you can access subfolders by referencing attributes that may or may not already exist.
# create a new subfolder called "January" by accessing it via attribute
january_folder = month_folder.january
Joining to a file will return a file object instead.
new_years_file = january_folder.join('Happy New Year.txt')
Files
First, we create an instance of the ExcelFile
class using the File
function. This occurs automatically by virtue of the .xlsx
file extension.
# create ExcelFile instance
file = File(r'C:\Users\MyID\Documents\MyFolder\MyFile.xlsx')
Next, let's check if the file exists. If not, let's save a pandas
DataFrame
as an Excel file.
# export a pd.DataFrame to the file, if it does not already exist
if not file.exists:
df = pd.DataFrame({'id': [1, 2, 3], 'data': ['a', 'b', 'c']})
file.save(df)
Creating MyFile.xlsx writing 72.00 B to 'Sheet1' tab... DONE writing 80.00 B to 'Sheet1' tab... DONE
Now let's read the file we created as a DataFrame
.
# read the file we created as a pd.DataFrame
df = file.read()
On second thought, let's delete the file.
# delete the file we created
file.delete()
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
Built Distribution
Hashes for pathpilot-0.1.6-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 08fb4d9a957f13ceb2f615e7d935e85fffdfcae6a3e43b74f0cdc699b34f0d25 |
|
MD5 | cdc604f85ce64b0c051ac9a8baf0ca49 |
|
BLAKE2b-256 | 8a36f16c1052af0ca9f4847d3ad30fa37c11f253f33a0bb937ad1eb0073c14f4 |