alisonpezzott/pyfabricops
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.
Welcome to pyfabricops
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.15
βοΈ Installation
pip install -U pyfabricopsπ οΈ Development setup
# Install uv
pip install uv
# Sync dev dependencies (creates .venv automatically)
uv sync --group devβοΈ Usage
Create a repository and clone it locally.
Create a notebook or a script and import the library:
# Import the library
import pyfabricops as pfSet 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
βββ graph/
β βββ __init__.py
β βββ users.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.pyLogging 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 messagestandard: Includes module name in compact formdetailed: 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
- Fork this repository
- Create a new branch (feat/my-feature)
- Run
uv sync --group devto set up the development environment - Run
uv run ruff format --check --diff . && uv run ruff check . - Run
uv run pytest -s -x --cov=pyfabricops -vto run tests - Submit a pull request to branch
developπ
π Publishing
For Maintainers
To publish a new version to PyPI:
- Update the version in
pyproject.tomlandsrc/pyfabricops/_version.py - Commit and push changes
- Create a new release on GitHub with a tag (e.g.,
v0.1.0) - The GitHub Action will automatically:
- Run tests
- Build the package
- Publish to PyPI
Testing with TestPyPI
# Build and publish to TestPyPI
uv build
uv publish --publish-url https://test.pypi.org/legacy/ --token <your-testpypi-token>
# Install from TestPyPI
pip install --index-url https://test.pypi.org/simple/ pyfabricopsPrerequisites for Publishing
- Set up a PyPI account at https://pypi.org/
- Generate an API token at https://pypi.org/manage/account/token/
- Add the token as
PYPI_TOKENsecret in GitHub repository settings
π 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 π