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
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
โโโ 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
poetry installto set up the development environment - Run
poetry run task testto 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
# 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
- 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 ๐
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pyfabricops-0.3.15.tar.gz.
File metadata
- Download URL: pyfabricops-0.3.15.tar.gz
- Upload date:
- Size: 83.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.3.2 CPython/3.11.14 Linux/6.14.0-1017-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e35c019753a269d7087d0d04302cf8b0446bd758b6edc27a6ab572136d5e88ac
|
|
| MD5 |
94ff98a4fb58d358509f55ef00778ff2
|
|
| BLAKE2b-256 |
d4553c5c25d96ac772cdcd80b720fe97db1ecb0e0c6565425db8076836db9b4d
|
File details
Details for the file pyfabricops-0.3.15-py3-none-any.whl.
File metadata
- Download URL: pyfabricops-0.3.15-py3-none-any.whl
- Upload date:
- Size: 120.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.3.2 CPython/3.11.14 Linux/6.14.0-1017-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
07882e94cc6f696f793793c8ccc388e95db5eedfe576d9694b9d373b0c88b6f3
|
|
| MD5 |
6331be71e31762ebb7d002235c91a959
|
|
| BLAKE2b-256 |
388a5d5fa5f9598b81edb9b74a32a4b87a970b64b83daa5c522347194dcf6224
|