Skip to content

A Python wrapper library for Microsoft Fabric and Power BI that provides a simple, consistent interface to the official Fabric REST APIs, with automatic fallback to Power BI REST APIs when required. Designed to run in Fabric notebooks, pure Python scripts, or as part of YAML-based CI/CD workflows.

License

Notifications You must be signed in to change notification settings

alisonpezzott/pyfabricops

Repository files navigation

Welcome to pyfabricops

PyPI version License: MIT Python versions Typing status
Tests

A Python wrapper library for Microsoft Fabric (and Power BI) operations, providing a simple interface to the official Fabric REST APIs. Falls back to Power BI REST APIs where needed. Designed to run in Python notebooks, pure Python scripts or integrated into YAML-based workflows for CI/CD. Access to the repositoy on GitHub.

πŸš€ Features

  • Authenticate using environment variables (GitHub Secrets, ADO Secrets, .env ...)
  • Manage workspaces, capacities, semantic models, lakehouses, reports and connections
  • Execute Git operations and automate Fabric deployment flows (Power BI inclusive)
  • Capture and Manage Git branches automatically for CI/CD scenarios
  • Many use cases and scenarios including yaml for test and deploy using GitHub Actions

πŸ“ƒ Documentation

Access: https://pyfabricops.readthedocs.io/en/latest/

βœ… Requirements

  • Requires Python >= 3.10 <=3.12.10

βš’οΈ Installation

pip install -U pyfabricops

βš™οΈ Usage

Create a repository and clone it locally. Create a notebook or a script and import the library:

# Import the library
import pyfabricops as pf

Set the authentication provider

Set auth environment variables acording to your authentication method

Environment variables (.env, GitHub Secrets, Ado Secrets...)

pf.set_auth_provider("env")

This is the default behavior. You can set these in a .env file or directly in your environment (GitHub Secrets, ADO Secrets...).

Example .env file:

FAB_CLIENT_ID=your_client_id_here
FAB_CLIENT_SECRET=your_client_secret_here
FAB_TENANT_ID=your_tenant_id_here
FAB_USERNAME=your_username_here   # Necessary for some functions with no SPN support
FAB_PASSWORD=your_password_here   # Necessary for some functions with no SPN support

OAuth (Interactive)

pf.set_auth_provider("oauth")

This will open a browser window for user authentication.

Fabric Notebook (Authenticated User)

pf.set_auth_provider("fabric")

This method is designed for use inside Microsoft Fabric notebooks where the user is already authenticated.
It uses notebookutils.credentials.getToken() to retrieve the access token automatically.
No browser authentication required - perfect for notebooks running in Fabric!

See more details in the authentication guide

Create a repository and clone it locally. Prepare your environment with the required variables according to your authentication method (GitHub Secrets, ADO Secrets, .env ...)

Branches configuration

Create a branches.json file in the root of your repository to define your branch mappings:

{
    "main": "-PRD",
    "master": "-PRD",
    "dev": "-DEV",
    "develop": "-DEV",
    "staging": "-STG"
}

This file maps your local branches to Fabric branches, allowing the library to automatically manage branch names for CI/CD scenarios.

πŸͺ„ Examples

Visit: https://github.com/alisonpezzott/pyfabricops-examples

🧬 Project Structure

src/
└── pyfabricops/
    β”œβ”€β”€ api/
    β”‚   β”œβ”€β”€ __init__.py
    β”‚   β”œβ”€β”€ api.py
    β”‚   β”œβ”€β”€ auth.py
    β”‚   └── scopes.py
    β”œβ”€β”€ cd/
    β”‚   β”œβ”€β”€ __init__.py
    β”‚   └── support_files.py
    β”œβ”€β”€ core/
    β”‚   β”œβ”€β”€ __init__.py
    β”‚   β”œβ”€β”€ capacities.py
    β”‚   β”œβ”€β”€ connections.py
    β”‚   β”œβ”€β”€ deployment_pipelines.py
    β”‚   β”œβ”€β”€ domains.py
    β”‚   β”œβ”€β”€ folders.py
    β”‚   β”œβ”€β”€ gateways.py
    β”‚   β”œβ”€β”€ gateways_encryp_creds.py
    β”‚   β”œβ”€β”€ git.py
    β”‚   β”œβ”€β”€ tags.py
    β”‚   └── workspaces.py
    β”œβ”€β”€ dmv/
    β”‚   β”œβ”€β”€ __init__.py
    β”‚   β”œβ”€β”€ dmv.py
    β”œβ”€β”€ helpers/
    β”‚   β”œβ”€β”€ __init__.py
    β”‚   β”œβ”€β”€ data_pipelines.py
    β”‚   β”œβ”€β”€ data_pipelines.py
    β”‚   β”œβ”€β”€ dataflows_gen1.py
    β”‚   β”œβ”€β”€ dataflows_gen2.py
    β”‚   β”œβ”€β”€ environments.py
    β”‚   β”œβ”€β”€ folders.py
    β”‚   β”œβ”€β”€ items.py
    β”‚   β”œβ”€β”€ lakehouses.py
    β”‚   β”œβ”€β”€ notebooks.py
    β”‚   β”œβ”€β”€ reports.py
    β”‚   β”œβ”€β”€ semantic_models.py
    β”‚   β”œβ”€β”€ warehouses.py
    β”‚   └── workspaces.py
    β”œβ”€β”€ items/
    β”‚   β”œβ”€β”€ __init__.py
    β”‚   β”œβ”€β”€ data_pipelines.py
    β”‚   β”œβ”€β”€ dataflows_gen1.py
    β”‚   β”œβ”€β”€ dataflows_gen2.py
    β”‚   β”œβ”€β”€ environments.py
    β”‚   β”œβ”€β”€ items.py
    β”‚   β”œβ”€β”€ lakehouses.py
    β”‚   β”œβ”€β”€ notebooks.py
    β”‚   β”œβ”€β”€ reports.py
    β”‚   β”œβ”€β”€ semantic_models.py
    β”‚   β”œβ”€β”€ shortcuts.py
    β”‚   β”œβ”€β”€ spark.py
    β”‚   β”œβ”€β”€ variable_libraries.py
    β”‚   └── warehouses.py
    β”œβ”€β”€ utils/
    β”‚   β”œβ”€β”€ __init__.py
    β”‚   β”œβ”€β”€ decorators.py
    β”‚   β”œβ”€β”€ exceptions.py
    β”‚   β”œβ”€β”€ logging.py
    β”‚   β”œβ”€β”€ schemas.py
    β”‚   └── utils.py
    β”œβ”€β”€ __init__.py
    └── _version.py

Logging configuration

The custom logging system implemented in pyfabricops provides a complete and flexible solution for monitoring and debugging the library.

🎨 Custom Formatting

  • Automatic colors: Different colors for each log level (DEBUG=Cyan, INFO=Green, WARNING=Yellow, ERROR=Red, CRITICAL=Magenta)
  • Multiple styles:
    • minimal: Only timestamp, level and message
    • standard: Includes module name in compact form
    • detailed: Complete format with all information

πŸŽ›οΈ Easy Configuration

import pyfabricops as pf

# Basic configuration
pf.setup_logging(level='INFO', format_style='standard')

# Debug mode for development
pf.enable_debug_mode(include_external=False)

# Disable logging completely
pf.disable_logging()

# Reset to default configuration
pf.reset_logging()

For complete logging configuration options, refer to the logging_system.md

❀️Contributing

  1. Fork this repository
  2. Create a new branch (feat/my-feature)
  3. Run poetry install to set up the development environment
  4. Run poetry run task test to run tests
  5. Submit a pull request πŸš€

πŸš€ Publishing

For Maintainers

To publish a new version to PyPI:

  1. Update the version in pyproject.toml and src/pyfabricops/_version.py
  2. Commit and push changes
  3. Create a new release on GitHub with a tag (e.g., v0.1.0)
  4. The GitHub Action will automatically:
    • Run tests
    • Build the package
    • Publish to PyPI

Testing with TestPyPI

# Configure TestPyPI
poetry config repositories.testpypi https://test.pypi.org/legacy/
poetry config pypi-token.testpypi <your-testpypi-token>

# Build and publish to TestPyPI
poetry build
poetry publish -r testpypi

# Install from TestPyPI
pip install --index-url https://test.pypi.org/simple/ pyfabricops

Prerequisites for Publishing

🐞 Issues

If you encounter any issues, please report them at https://github.com/alisonpezzott/pyfabricops/issues

βš–οΈ License

This project is licensed under the MIT License – see the LICENSE file for details.

🌟 Acknowledgements

Created and maintained by Alison Pezzott Feedback, issues and stars are welcome 🌟

YouTube subscribers GitHub followers LinkedIn Discord Telegram Instagram

About

A Python wrapper library for Microsoft Fabric and Power BI that provides a simple, consistent interface to the official Fabric REST APIs, with automatic fallback to Power BI REST APIs when required. Designed to run in Fabric notebooks, pure Python scripts, or as part of YAML-based CI/CD workflows.

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project

 

Languages