A Pythonic Power Query (.pq) File Manager for Excel & Power BI Automation
Project description
๐ xl-pq-handler
๐งฉ A Pythonic Power Query (.pq) File Manager for Excel & Power BI Automation
๐ง What is xl-pq-handler?
xl-pq-handler is a Python UI App + library built for developers, data analysts, and automation engineers who work with Power Query (.pq) files in Excel or Power BI.
It lets you:
- ๐ Parse, search, and index
.pqscripts - ๐ Copy Power Query code to clipboard
- ๐ช Insert queries directly into Excel workbooks
- ๐งพ Maintain YAML-based metadata (name, category, tags, description, version)
- ๐ Export, validate, and refresh PQ indexes
- โก Batch-insert queries for rapid Excel automation
All from Python. No manual clicks. No clutter. ๐
Stop the cap. Managing Power Query
.pqfiles is low-key a nightmare.This tool is the ultimate glow-up for your M-code. ๐
It's not just a library; it's your new Power Query IDE.
๐ซ The Struggle is Real (Before)
- Copy-pasting M-code between 8 different Excel files.
- Forgetting which queries depend on
fn_Helper_v2_final. - Your
Downloads/PQfolder looks like a bomb went off. - Manually updating a query in 3 different workbooks. ๐
๐ The Vibe (After)
- Launch a sleek UI that shows your entire
.pqlibrary. - Right-click a query -> "Insert" -> pick your open Excel file from a dropdown. Done.
- Right-click -> "Edit Metadata" -> change
category-> the app auto-moves the file to the new folder. ๐คฏ - Click the "Graph" tab to see all the dependencies. No more guessing.
This is that main character energy for your data workflow.
โจ The Features Actually Slap
This tool is a whole mood. It's a UI app and a Python library.
๐ฅ๏ธ The UI App (Your New BFF)
Forget scripts. Just launch the app from your terminal. This is your mission control.
python -m xl_pq_handler "path/to/your/repo"
๐ฅ Smart Extract (The "Yoink")
- Yank from File: Pick any
.xlsxand rip all its queries. - Yank from Open WB: Don't even know where the file is? Just pick from a dropdown of all your open workbooks. Bet.
๐ช Dependency-Aware Insert (The "Yeet")
- Select a query. This tool auto-finds all its dependencies.
- It inserts them in the correct order.
- Pick your target: Don't just spray and pray into your active workbook. A dropdown shows all open workbooks so you can snipe the exact one you want.
โ๏ธ Edit & Sync (The "Glow-Up")
- Right-click any query to edit its metadata (name, category, tags, deps).
- The best part: You change the
categoryfrom "Staging" to "Production"? The app auto-moves the.pqfile from theStaging/folder to theProduction/folder. IYKYK. ๐คฏ
๐ See the Receipts (Dependency Graph)
- Tired of guessing what a query needs?
- Click a query -> click the "Graph" tab.
- See a beautiful tree of all its dependencies, right there. No cap.
๐ป "I'm Out" (External Editor)
- Need to edit the actual M-code?
- Right-click -> "Open in Editor."
- This instantly opens the file in VS Code (or Notepad, if you're basic) for you to edit. Save, go back to the app, hit refresh. โจ
๐ง The Brain (For Scripting)
- Under the hood is the
PQManager, a sick Python library. - Use it in your own automation scripts for all the features above, but headless. ๐ค
๐ฆ Get it Already (Installation)
pip install xl-pq-handler
(^ above installs all of the dependencies - customtkinter, xlwings, pydantic, pyyaml, pandas, & filelock too!)
๐ How to Vibe
1. The Main Way (The UI) ๐
This is what you want. Open your terminal and run this.
# Launch the UI
# Point it at the folder where you store your .pq files
python -m xl_pq_handler "D:\My-Power-Query-Repo"
(If you set up the script, you can just do pq-magic "...")
Then just... click buttons. It's that easy.
2. The Automation Way (Python Script) ๐ค
For your main.py automation scripts, use the PQManager.
from xl_pq_handler import PQManager
# Point it at your repo
manager = PQManager(r"D:\My-Power-Query-Repo")
# Rebuild index (good practice)
manager.build_index()
# ---- SCRIPTING EXAMPLE ----
# Insert "FinalReport" + all its dependencies
# into a *specific* open workbook named "Dashboard.xlsm"
queries_to_add = ["FinalReport"]
try:
manager.insert_into_excel(
names=queries_to_add,
workbook_name="Dashboard.xlsm" # <-- So clean!
)
print("๐ Queries sent! Go be a hero.")
except Exception as e:
print(f"๐ฌ Bruh, it failed: {e}")
๐ The Drip (File Structure)
This is how you organize your repo. The app does the rest.
My-Power-Query-Repo/
โ
โโโ index.json <-- The app makes this. Don't touch.
โ
โโโ API/ <-- "API" Category
โ โโโ Get_API_Data.pq
โ โโโ fn_Get_Credentials.pq
โ
โโโ Helpers/ <-- "Helpers" Category
โ โโโ fn_Format_Date.pq
โ โโโ fn_Safe_Divide.pq
โ
โโโ Reports/ <-- "Reports" Category
โโโ Final_Sales_Report.pq
Each .pq file is just M-code with a YAML "frontmatter" block at the top. This is the metadata.
---
name: Final_Sales_Report
category: Reports
tags: [sales, final, public]
dependencies:
- Get_API_Data
- fn_Format_Date
description: The main query for the monthly sales dashboard.
version: 1.5
---
(let
Source = Get_API_Data(),
#"Formatted Date" = fn_Format_Date(Source, "DateColumn")
in
#"Formatted Date")
๐ License
This project is licensed under the GNU-GPL 3.0 License. Go wild.
๐ Credits
Made by Sudharshan TK (tks18)
If this tool just saved your workflow, give it a โญ Star on GitHub!
โก โAutomate the boring Power Query stuff โ one
.pqat a time.โ
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 xl_pq_handler-2.3.0.tar.gz.
File metadata
- Download URL: xl_pq_handler-2.3.0.tar.gz
- Upload date:
- Size: 36.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.9.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
67cf57d9d2514a4b054713fe0b1bc901028012152257f14e2bac4c3be8394bad
|
|
| MD5 |
5d6dce8704ab591fbe754dbc972617cb
|
|
| BLAKE2b-256 |
bce43ebc2611ccae2d32c9e310d296613ae4f6771dc4fe54b517a6b0bc536d32
|
File details
Details for the file xl_pq_handler-2.3.0-py3-none-any.whl.
File metadata
- Download URL: xl_pq_handler-2.3.0-py3-none-any.whl
- Upload date:
- Size: 53.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.9.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b09f47f1dc59d21ef7fb7371a1b37737b81fe726e1a5e562b9cbe8a1171ab8fc
|
|
| MD5 |
3a177a40dc8c8beb5825327ed0949233
|
|
| BLAKE2b-256 |
9746a2863d9be32e3189b82bed928db3fa6a530332b77854ce320025f08ebd8e
|