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)
- Deploy from Git with a plan:
plan_all_items()shows what would change, anddeploy_all_items()deploys only what changed since the last deployment, in dependency order, with the state and a lock per environment kept in OneLake (Deployment) - Tell how a workspace stands against the source with
reconcile_items(), and restore what drifted withrestore_items()(Reconciliation) - 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 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
By default the "env" provider uses the Service Principal (client_credentials) flow.
To authenticate as a user (ROPC / password grant) — e.g. in CI/CD pipelines where a
Service Principal is not available — pass credential_type="user":
pf.set_auth_provider("env", credential_type="user")
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
The examples/ folder has runnable examples:
- a sample workspace with a lakehouse, notebooks, a pipeline, a semantic model and a report;
- scripts that authenticate, export a workspace and deploy the sample, fully or only what changed;
- a reconciliation that reports drift, and can restore it;
- CI definitions for Azure DevOps and GitHub Actions.
More examples: 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.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 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, then runuv lock - Add the version's section to
CHANGELOG.md - Commit and push changes
- Create a new release on GitHub, tagged
vand the version (e.g.,v0.7.0) - The GitHub Action will automatically:
- Check that the tag matches the version
- Run tests
- Build and check 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/ pyfabricops
Prerequisites 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 🌟
Release files for pyfabricops 0.7.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| pyfabricops-0.7.0.tar.gz | 2.0 MB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pyfabricops-0.7.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 2.2 MB
Release files / pyfabricops-0.7.0.tar.gz
| Download URL | pyfabricops-0.7.0.tar.gz |
|---|---|
| Size | 2.0 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
984a4523bf667b70846fa901bd8b9afda0f429890bc8cdc71ab4c28d8aafba09
|
|
BLAKE2b-256 checksum How to use checksums |
2b5c8434aa1622c93efd0cdd6f6ed1481363d28636abf2f430dbcbbdcffda434
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.12.19 {"installer":{"name":"uv","version":"0.12.19","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / pyfabricops-0.7.0-py3-none-any.whl
| Download URL | pyfabricops-0.7.0-py3-none-any.whl |
|---|---|
| Size | 193.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e9362a386eedd10f3269c2805d3a22ecafca9a3860477eacac4bf3ba1755a59d
|
|
BLAKE2b-256 checksum How to use checksums |
67cd4a53b49429c2c1ebb0f7f8c3898fe517b2def5b7f2f809cb6a439a497fc3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.12.19 {"installer":{"name":"uv","version":"0.12.19","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|