How quangtrinh1612/powerbi-api works
Project Type & Purpose
• This is a Python client library designed to interact with Microsoft Power BI REST APIs.
• Its purpose is to provide an object-oriented interface that encapsulates operations for handling dashboards, datasets, reports, dataflows, workspaces, and users in Power BI.
• It emphasizes modularity (with dedicated service modules for each entity), token-based authentication, centralized logging, and robust session management.
Analyzing the File Structure
• Key top-level files:
• main.py: The entry point for running the application.
• README.md & requirements.txt: Documentation and dependency management.
• config/: Contains configuration files such as logging.yaml.
• The “powerbi” directory is the heart of the project:
• Contains modules like auth.py, client.py, logger.py, session.py, config.py, enums.py, and utils.py.
• The “services” subdirectory encapsulates entity-specific operations (e.g., datasets, dashboards, reports, etc.) and clearly defines boundaries for each function.
• Testing and scripting directories indicate support for automated unit tests (test/) and additional utility scripts (script/).
Core Components
a. Main Application & Entry Point:
• main.py: Initiates the application and ties together configuration, authentication, and session management.
b. API Client & Session Management:
• client.py: Acts as the primary interface with Power BI REST API.
• session.py: Handles HTTP requests and manages session state, including token injection.
c. Authentication & Security:
• auth.py: Implements token-based authentication with Power BI’s API.
d. Configuration & Logging:
• config.py & config/logging.yaml: Manage API endpoints, credentials, and logging settings.
• logger.py: Centralizes logging configuration and sends logs to both console and files.
e. Modular Services (Business Logic Components):
• The services folder: Contains distinct modules such as datasets.py, dashboards.py, reports.py, etc.
• These modules are loosely coupled and focus on a specific aspect of Power BI management.
f. Utility & Enum Definitions:
• utils.py: Houses helper functions.
• enums.py: Defines enumerations for Power BI entities, ensuring consistency across the modules.
g. External Dependencies:
• Microsoft Power BI REST APIs: All client operations ultimately call these external endpoints.
• Application Layer (main.py): The entry point.
• Core Library Layer (powerbi package): Include a central block for the API client and session/auth handling.
• Service Modules (inside the services subdirectory): Individual blocks for datasets, dashboards, reports, etc.
• Supporting configurations (config and environment variables) and logging utilities.
• Relationships and data flows:
• That the client uses session management to interact with the Power BI REST API.
• That each service module depends on the client for its operations.
• Configuration (config.py and logging.yaml) to both the client and logger modules.
• Integrations (e.g., token injection from auth.py to session.py; logging output directed to external log files and console).
Architectural Patterns & Design Principles
• Modularization: Separation of distinct functionalities into dedicated modules (authentication, API calling, specific service operations).
• Separation of Concerns: Configurations, logging, and session management are clearly separated, enhancing maintainability.
• Extensibility: The clear directory layout for services allows new modules (e.g., additional data management features) to be added easily.
• Encapsulation: The client abstracts complexities (e.g., HTTP session, token management) from individual service modules.