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 Vibe Check: Before vs. After
(The PQ IDE You Didn't Know You Needed โจ)
| Before xl-pq-handler ๐ซ | After xl-pq-handler ๐ |
|---|---|
| Endless copy-pasting M-code | One-click insert into any open Excel workbook |
Forgetting fn_Helper_v3 needs fn_Util_v1 |
Dependency graph shows you the whole family tree ๐ณ |
| decentralized file organization | Auto-organized folders based on category |
| Editing metadata = Manual YAML torture | Right-click -> Edit Metadata -> Save -> Done โ |
| "Which file uses that API?" -> ๐คทโโ๏ธ | Data Sources tab spills the tea โ |
| Blindly extracting queries from huge files | Preview before you extract, with syntax colors! |
| Updating one function in 5 workbooks manually | Edit once -> Refresh UI -> Insert where needed |
This is that main character energy for your data workflow.
โจ Features That Absolutely Slap
This ain't your grandpa's script library. We got a whole ecosystem:
๐ฅ๏ธ The UI App (Your New Dashboard)
- Launch a dedicated desktop app straight from your terminal. No more sad script outputs.
- Visually browse, search, and filter your entire
.pqlibrary like a pro. - It's got that dark mode aesthetic. You know the vibes. โจ
๐ฅ Smart Extract ("Yoink! Button")
- From File: Point it at any
.xlsx/.xlsm/.xlsband instantly rip out all the Power Queries. - From Open Workbook: Got 5 Excels open? No stress. A dropdown lists all open workbooks. Pick one, hit extract. Easy.
- Preview Before Saving: See the code (with syntax highlighting!), parameters, and data sources before you commit to saving the
.pqfile. No more blind extraction!
๐ช Dependency-Aware Insert ("Yeet Button")
- Select a query (e.g.,
FinalReport). The app automatically knows it needsGetSalesDataandfn_FormatDate. - It yeets all required queries into Excel in the correct order. ๐คฏ
- Target Practice: Don't just spray into the active workbook. Use the dropdown to select exactly which open workbook gets the queries. Precision!
โ๏ธ Edit Metadata + Auto-Sync ("The Organizer")
- Right-click a query -> "Edit Metadata."
- Change the
name,tags,dependencies,description,version. - The Magic โจ: Change the
categoryfromStagingtoProduction? The app automatically moves the.pqfile to theProduction/folder. Chef's kiss! ๐ค
๐ Syntax Highlighting ("Make it Pretty")
- See your M-code in the Preview tabs (Library, Edit, Extract) with VS Code-style syntax highlighting. Keywords, functions, strings, comments โ all colored up. โจ
๐ง Code Intelligence ("The Brain")
- Parameter Peek: Select a function query, and the "Parameters" tab shows its inputs, types (
any,text, etc.), and if they'reoptional. - Data Source Detective: The "Data Sources" tab scans the code and lists out all the external connections (
Sql.Database,Web.Contents,File.Contents, etc.) and whether the source is a literal string or an input parameter. Big for security audits! ๐ต๏ธโโ๏ธ - Dependency Deets:
- Auto-Detect: Click the button in the Edit dialog to automatically scan the code and suggest the
dependencies. Saves so much typing. - Visual Graph: The "Graph" tab shows a slick tree view of a query's entire dependency chain. No more surprises. ๐ณ
- Auto-Detect: Click the button in the Edit dialog to automatically scan the code and suggest the
๐ป External Editor Escape Hatch ("Send It")
- Need to tweak the actual M-code logic?
- Right-click -> "Open in Editor."
- Instantly opens the
.pqfile in VS Code (if it's in your PATH) or falls back to Notepad. Edit, save, hit refresh in the UI. Seamless.
๐ค Python Backend (PQManager)
- All the power, none of the clicks. Import
PQManagerinto your own Python automation scripts. - Headless extraction, insertion, index building โ you name it. Perfect for CI/CD or scheduled tasks.
๐ฆ Get it Already (Installation)
pip install xl-pq-handler
(This single command grabs everything you need: customtkinter, xlwings, pydantic, pyyaml, pandas, filelock โ the whole squad.)
๐ How to Vibe
1. The Main Way (The UI) ๐
This is the main event. Open your terminal:
# Better launch - point it at your actual PQ repo folder
python -m xl_pq_handler "D:\Path\To\Your\PowerQuery_Repo"
# Or even better way
pqmagic "D:\Path\To\Your\PowerQuery_Repo"
Now just... use the app. Click around. It's built different. ๐
Then just... click buttons. It's that easy.
2. ๐ค Script Kiddie Corner (Python Usage)
For your main.py automation scripts, use the PQManager.
from xl_pq_handler import PQManager
# Point manager at your repo
manager = PQManager(r"D:\Path\To\Your\PowerQuery_Repo")
# Rebuild index (always a good move)
manager.build_index()
# ---- EXAMPLE: INSERT INTO SPECIFIC WORKBOOK ----
target_workbook = "Monthly_Report_WIP.xlsx" # Must be open!
queries_needed = ["Calculate_KPIs", "Generate_Summary"]
try:
manager.insert_into_excel(
names=queries_needed,
workbook_name=target_workbook # <-- Target acquired ๐ฏ
)
print(f"๐ Sent queries to {target_workbook}. Mission accomplished.")
except Exception as e:
print(f"๐ญ Insert failed: {e}")
# ---- EXAMPLE: EXTRACT FROM FILE ----
source_file = r"C:\Downloads\NewDataSource.xlsx"
try:
manager.extract_from_excel(category="Downloaded", file_path=source_file)
print(f"โ
Successfully yoinked queries from {source_file}!")
except Exception as e:
print(f"๐ Extraction 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: Clean_RawSales # The query's name in Excel/PBI
category: Staging # Matches the folder name (keep it sync'd!)
tags: [cleaning, sales, raw] # Searchable tags
dependencies: # List other queries *this one* calls
- fn_FormatDate
description: Cleans and transforms the raw monthly sales data dump. # What it does
version: 2.1 # Your version number
---
let # Start of your actual M-code
Source = Csv.Document(File.Contents("path/to/raw.csv"), ...),
#"Formatted Date" = fn_FormatDate(Source, "OrderDate")
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.3.tar.gz.
File metadata
- Download URL: xl_pq_handler-2.3.3.tar.gz
- Upload date:
- Size: 37.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.9.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
373900f730867044b7a11fff364a5bd7fdee2dd427adcbbb111b62817be10a19
|
|
| MD5 |
a0665e80b2d56a8cf291048cb6ce0e82
|
|
| BLAKE2b-256 |
80ee11cdd5978c510750df1e66f22c9f7d868d806b47c9415f86b0018311f6ea
|
File details
Details for the file xl_pq_handler-2.3.3-py3-none-any.whl.
File metadata
- Download URL: xl_pq_handler-2.3.3-py3-none-any.whl
- Upload date:
- Size: 54.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.9.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e694ab3dc37fc840c6e817b829e760b84cee89377f64a10d9447788d119f5082
|
|
| MD5 |
f8a7c51ed1433d2b9ae16d6510f71149
|
|
| BLAKE2b-256 |
2f12396f9885fb64f129083abc6e21d55616b0bb181e7722bcb72e0704673a9e
|