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 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 .pq library 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 / .xlsb and 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 .pq file. No more blind extraction!

๐Ÿช„ Dependency-Aware Insert ("Yeet Button")

  • Select a query (e.g., FinalReport). The app automatically knows it needs GetSalesData and fn_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 category from Staging to Production? The app automatically moves the .pq file to the Production/ 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're optional.
  • 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. ๐ŸŒณ

๐Ÿ’ป External Editor Escape Hatch ("Send It")

  • Need to tweak the actual M-code logic?
  • Right-click -> "Open in Editor."
  • Instantly opens the .pq file 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 PQManager into 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 .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.2.tar.gz (37.5 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.2-py3-none-any.whl (54.5 kB view details)

Uploaded Python 3

File details

Details for the file xl_pq_handler-2.3.2.tar.gz.

File metadata

  • Download URL: xl_pq_handler-2.3.2.tar.gz
  • Upload date:
  • Size: 37.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.5

File hashes

Hashes for xl_pq_handler-2.3.2.tar.gz
Algorithm Hash digest
SHA256 6755fb72c5a8c822efc4506934a494a06044e502183cb52dd292bd69b27e0773
MD5 110151377911e08710d89683f6c89f00
BLAKE2b-256 96ca1d4fcddb1fbfb665c6ca2ae5fd9d1e3d2440fed604d399e7766d5402d293

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for xl_pq_handler-2.3.2-py3-none-any.whl
Algorithm Hash digest
SHA256 42582146dac381e47f32b491b09041e0e7984a30f108d070c0e70b8a36033b8d
MD5 2285862c75a20f8237468fc87c4f6175
BLAKE2b-256 0fde019cedd55d37b47def419ef922e020d150dafb93f900793bca14ebf0550d

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