Skip to main content

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

PyPI Version Python Versions License


๐Ÿง  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 .pq scripts
  • ๐Ÿ“‹ 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 .pq files 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/PQ folder 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 .pq library.
  • 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 .xlsx and 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 category from "Staging" to "Production"? The app auto-moves the .pq file from the Staging/ folder to the Production/ 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 .pq at a time.โ€


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

xl_pq_handler-2.3.0.tar.gz (36.1 kB view details)

Uploaded Source

Built Distribution

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

xl_pq_handler-2.3.0-py3-none-any.whl (53.1 kB view details)

Uploaded Python 3

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

Hashes for xl_pq_handler-2.3.0.tar.gz
Algorithm Hash digest
SHA256 67cf57d9d2514a4b054713fe0b1bc901028012152257f14e2bac4c3be8394bad
MD5 5d6dce8704ab591fbe754dbc972617cb
BLAKE2b-256 bce43ebc2611ccae2d32c9e310d296613ae4f6771dc4fe54b517a6b0bc536d32

See more details on using hashes here.

File details

Details for the file xl_pq_handler-2.3.0-py3-none-any.whl.

File metadata

File hashes

Hashes for xl_pq_handler-2.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b09f47f1dc59d21ef7fb7371a1b37737b81fe726e1a5e562b9cbe8a1171ab8fc
MD5 3a177a40dc8c8beb5825327ed0949233
BLAKE2b-256 9746a2863d9be32e3189b82bed928db3fa6a530332b77854ce320025f08ebd8e

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