Skip to main 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.

Project description

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

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

pyfabricops-0.3.10.tar.gz (82.6 kB view details)

Uploaded Source

Built Distribution

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

pyfabricops-0.3.10-py3-none-any.whl (118.2 kB view details)

Uploaded Python 3

File details

Details for the file pyfabricops-0.3.10.tar.gz.

File metadata

  • Download URL: pyfabricops-0.3.10.tar.gz
  • Upload date:
  • Size: 82.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.3.2 CPython/3.11.14 Linux/6.11.0-1018-azure

File hashes

Hashes for pyfabricops-0.3.10.tar.gz
Algorithm Hash digest
SHA256 15488d7dca7b8f0e3989771eb85dcf26ac840487b71ca0578d4f5a9207a75694
MD5 b9f2a75b0f72f24d2bf371b004c67242
BLAKE2b-256 af3a4d8db0e8ad1018ff78fdbab3166577ffcbfec7da992068ea8d0472188b87

See more details on using hashes here.

File details

Details for the file pyfabricops-0.3.10-py3-none-any.whl.

File metadata

  • Download URL: pyfabricops-0.3.10-py3-none-any.whl
  • Upload date:
  • Size: 118.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.3.2 CPython/3.11.14 Linux/6.11.0-1018-azure

File hashes

Hashes for pyfabricops-0.3.10-py3-none-any.whl
Algorithm Hash digest
SHA256 eeb6ad2ac6aa97460ca0fdfe5b489650e90f020e351672afe93cd39c18d9a449
MD5 37203b9bf230fdeb10ef7d3dea799834
BLAKE2b-256 db8b0ed9e8988fc5789914c00b86993a5949c4fa727af77a180ee20d66e1e7e7

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