Skip to main content

Simple file discovery and Excel processing toolkit for document workflows

Project description

๐Ÿ“ filekit

Simple file discovery and Excel processing toolkit.

Find files by type โ†’ Copy/Move โ†’ Process Excel โ†’ Get DataFrame

Python 3.10+ License: MIT Version


๐Ÿš€ Quick Start

Installation

pip install filekit-ljd

Basic Usage

from filekit import find, ops

# Find the latest Manpower Budget file from predefined paths
file = find.manpower_budget()

# Copy to a local backup folder
backup = file.copy(r"C:\Temp\Backup")

# Process the Excel sheet and get a clean DataFrame
df = ops.clean_sheet(file, sheet="Sheet1", output=r"C:\Temp\result.xlsx")

print(df.head())

โœจ Features

  • Smart file discovery โ€” finds the most recent file of a given type from predefined folder lists
  • Type-aware sorting โ€” each file type uses its own versioning/date logic (revision numbers, months, quarters)
  • Fluent file operations โ€” chainable .copy() and .move() that return new FileObject instances
  • Excel merged-cell expansion โ€” flattens merged cells into a normalized Datos_Limpios sheet before reading
  • Pandas integration โ€” every Excel processing call returns a pd.DataFrame ready for analysis
  • Progress feedback โ€” large Excel files show a tqdm progress bar automatically
  • Graceful not-found handling โ€” FileObject evaluates to False when no file is found, so if file: checks just work

๐Ÿ“ฆ Installation

pip install filekit-ljd

Requirements

Package Minimum version
Python 3.10+
openpyxl 3.1.5+
pandas 3.0.2+
tqdm 4.67.3+

๐Ÿ“– API Documentation

find โ€” File Discovery

Import the singleton namespace:

from filekit import find

All methods search the predefined paths in paths_config.py and return a FileObject.

Method Searches for
find.manpower_budget() Latest Manpower Budget file (sorted by revision + month)
find.manpower_documents() Latest Manpower Documents file (sorted by year, month, quarter)
find.manpower() Latest general Manpower file (sorted by month + day)
find.zj() Latest ZJ production file (sorted by date + version)
find.real_time_production() Latest Real-Time Production file

FileObject โ€” File Wrapper

FileObject wraps the path returned by find.*() and exposes file operations.

file = find.manpower_budget()

# Check if a file was found
if file:
    print(f"Found: {file}")          # str(file) โ†’ full path string

# Copy to a destination folder (creates folders as needed)
backup = file.copy(r"C:\Backup")    # โ†’ FileObject pointing to the copy

# Move to a destination folder
archived = file.move(r"C:\Archive") # โ†’ FileObject pointing to the new location
Method / Usage Description
str(file) Returns the full file path as a string
bool(file) True if a file was found, False otherwise
file.copy(destination) Copies file to destination/ and returns a new FileObject
file.move(destination) Moves file to destination/ and returns a new FileObject

copy() and move() are chainable โ€” both return a FileObject so you can keep operating on the result.


ops โ€” Excel Processing

Import the singleton namespace:

from filekit import ops

ops.clean_sheet(file, sheet, output)

Expands merged cells in an Excel sheet and returns a pd.DataFrame.

df = ops.clean_sheet(
    file,               # FileObject, str, or Path
    sheet="Sheet1",     # Sheet name to process (default: "Sheet1")
    output=None,        # Optional output path
)
Parameter Type Description
file FileObject | str | Path Source Excel file
sheet str Sheet name to read (default "Sheet1")
output str | Path | None If given, saves a new file with only the cleaned sheet; if None, overwrites the original

Returns: pd.DataFrame โ€” first row used as column headers.

If sheet does not exist, the processor automatically falls back to the first sheet whose name contains "sheet" (case-insensitive).


Low-level utilities

These are used internally but can be imported for custom workflows:

from filekit.fileSelector import find_in_folder
from filekit.scanNameFiles import identify_file_type, get_file_info
from filekit.core.clean_sheet import CleanSheetProcessor, clean_sheet

find_in_folder(folder_path, file_type)

Searches a single folder for the most recent file of the given type.

path = find_in_folder(r"C:\Reports", "MANPOWER_BUDGET")
# Returns: str path or None

identify_file_type(file_path)

Identifies the type of a file based on its name alone.

identify_file_type("Manpower budget 2026 Rev 3.xlsx")  # โ†’ "MANPOWER_BUDGET"
identify_file_type("ZJ26042804-8170.xlsx")             # โ†’ "ZJ"
identify_file_type("Real-Time Production May.xlsx")    # โ†’ "REAL_TIME_PRODUCTION"

CleanSheetProcessor โ€” step-by-step processing

Low-level class for fine-grained control over the Excel processing pipeline:

from filekit.core.clean_sheet import CleanSheetProcessor

processor = CleanSheetProcessor(ruta="data.xlsx", nombre_hoja_origen="Sheet1")
processor.abrir()
processor.aplanar_merged_cells()
processor.guardar(ruta_salida="output.xlsx")
df = processor.obtener_dataframe()

๐Ÿ—๏ธ Project Structure

filekit/
โ”œโ”€โ”€ finder/
โ”‚   โ””โ”€โ”€ simple.py           # find API โ€” locates files by type from predefined paths
โ”œโ”€โ”€ operations/
โ”‚   โ””โ”€โ”€ simple.py           # ops API โ€” Excel processing operations
โ”œโ”€โ”€ core/
โ”‚   โ”œโ”€โ”€ file.py             # FileObject โ€” wraps paths with copy/move operations
โ”‚   โ””โ”€โ”€ clean_sheet.py      # CleanSheetProcessor โ€” expands merged cells, returns DataFrame
โ”œโ”€โ”€ fileSelector.py         # find_in_folder โ€” single-folder file search
โ”œโ”€โ”€ scanNameFiles.py        # identify_file_type โ€” name-based type detection
โ”œโ”€โ”€ validators.py           # Format validators for ZJ, Manpower subtypes
โ””โ”€โ”€ paths_config.py         # DEFAULT_PATHS โ€” predefined search directories

Module responsibilities

Module Responsibility
finder/ Orchestrates search across all predefined paths for a given type
operations/ High-level Excel processing, returns DataFrame
core/file.py Chainable file copy/move wrapper
core/clean_sheet.py Merged-cell expansion and DataFrame extraction
fileSelector.py Single-folder search, delegates type detection to scanNameFiles
scanNameFiles.py Identifies file type from filename patterns
validators.py Validates ZJ format (ZJ{YYMMDD}{DD}-{version}) and Manpower subtypes
paths_config.py Central dictionary of per-type search directories

๐Ÿ’ก Examples

Example 1 โ€” Basic file discovery

from filekit import find

file = find.manpower_budget()

if file:
    print(f"Found: {file}")
else:
    print("No Manpower Budget file found in configured paths.")

Example 2 โ€” Copy and process in one chain

from filekit import find, ops

file = find.manpower_budget()

# Copy to a working directory, then process the copy
working_copy = file.copy(r"C:\Work\Temp")
df = ops.clean_sheet(working_copy, sheet="Sheet1")

print(f"Rows: {len(df)}, Columns: {len(df.columns)}")
print(df.head())

Example 3 โ€” Save cleaned Excel and get DataFrame

from filekit import find, ops

file = find.zj()
df = ops.clean_sheet(
    file,
    sheet="Data",
    output=r"C:\Reports\ZJ_clean.xlsx",   # saves a new file with only the clean sheet
)

# Continue analysis
summary = df.groupby("Line").sum()

Example 4 โ€” Operation chaining

from filekit import find, ops

# Find โ†’ archive the original โ†’ process the archive
df = ops.clean_sheet(
    find.manpower().move(r"C:\archive"),
    sheet="Sheet1",
    output=r"C:\processed\manpower_clean.xlsx",
)

Example 5 โ€” Custom folder search (no predefined paths)

from filekit.fileSelector import find_in_folder
from filekit.core.file import FileObject
from filekit import ops

path = find_in_folder(r"C:\MyReports", "MANPOWER_BUDGET")
if path:
    file = FileObject(path)
    df = ops.clean_sheet(file, sheet="Budget")

โš™๏ธ Configuration

Predefined Paths

Edit filekit/paths_config.py to configure which folders each file type searches:

DEFAULT_PATHS = {
    "MANPOWER_BUDGET": [
        r"\\server\share\Manpower\Budget 2026",
        r"\\server\share\Manpower\Budget 2025",   # fallback
    ],
    "MANPOWER": [
        r"\\server\share\Manpower",
    ],
    "ZJ": [
        r"\\server\share\Production\ZJ",
    ],
    "MANPOWER_DOCUMENTS": [
        r"\\server\share\Manpower\Documents",
    ],
    "REAL_TIME_PRODUCTION": [
        r"\\server\share\Production\RealTime",
    ],
}
  • Each key maps to a list of folders โ€” tried in order, search stops at the first folder that yields a match.
  • Types not present in DEFAULT_PATHS will return an empty FileObject from find.*().

๐Ÿ“‚ Supported File Types

Type key Identified by Latest-file logic
MANPOWER_BUDGET "MANPOWER" + "BUDGET" in filename Highest revision number, then month
MANPOWER_DOCUMENTS "MANPOWER" + "DOCUMENTS" in filename Latest year, then month, then quarter
MANPOWER "MANPOWER" (no Budget/Documents) Latest month + day
ZJ Starts with "ZJ", format ZJ{YYMMDD}{DD}-{version} Latest date, then version number
REAL_TIME_PRODUCTION "REAL-TIME" + "PRODUCTION" in filename First match (single expected file)

ZJ format example: ZJ26042804-8170.xlsx โ†’ date 260428 (YYMMDD), version prefix 04, version 8170.
Files with (1), (2) suffixes are treated as duplicates and sorted accordingly.


๐Ÿ“„ License

MIT License โ€” see LICENSE for details.


๐Ÿ‘ค Author

LJD-UwU

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

filekit_ljd-0.2.0.tar.gz (20.5 kB view details)

Uploaded Source

Built Distribution

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

filekit_ljd-0.2.0-py3-none-any.whl (20.2 kB view details)

Uploaded Python 3

File details

Details for the file filekit_ljd-0.2.0.tar.gz.

File metadata

  • Download URL: filekit_ljd-0.2.0.tar.gz
  • Upload date:
  • Size: 20.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.9

File hashes

Hashes for filekit_ljd-0.2.0.tar.gz
Algorithm Hash digest
SHA256 e6f9e6af73628e18f42695192e74f61160ace339b197364e9691ae6fb714bc0c
MD5 d02f721c40b04bdf317599f3eda7d406
BLAKE2b-256 3abfa36e8ad687957835051bc5ccf40aa62120e4d391dda0ddefc956ab2cb722

See more details on using hashes here.

File details

Details for the file filekit_ljd-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: filekit_ljd-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 20.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.9

File hashes

Hashes for filekit_ljd-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 eafb88feb8369ae86b1e0c044fcb3468ab343f4724f739a89ea3567daa20e717
MD5 30a2fde73848f332429d51052dcb48a8
BLAKE2b-256 83037187f412a0f4d50abf30bd4becc085025b74740d508829092929b3fb935b

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