### Run MCP Server Example Script Source: https://github.com/tideseed/eptr2/blob/main/TESTING_GUIDE.md Execute the mcp_server_example.py script to view MCP server configuration, available tools, and example queries. Use the --run flag to start the server. ```bash python examples/mcp_server_example.py --run ``` -------------------------------- ### Run Live Tutorial App Source: https://github.com/tideseed/eptr2/blob/main/README.md Start the live tutorial Streamlit app to explore the package's functionality. Ensure Streamlit is installed. Provide your username and password for authentication. ```python from eptr2.tutorials import run_demo_app run_demo_app(username="YOUR_USERNAME",password="YOUR_PASSWORD") ``` -------------------------------- ### Configuration Examples Source: https://github.com/tideseed/eptr2/blob/main/docs/api/mcp.md Examples for configuring the MCP server in different environments. ```APIDOC ## Configuration Examples ### Claude Desktop Configuration Add the following to `claude_desktop_config.json`: ```json { "mcpServers": { "eptr2": { "command": "eptr2-mcp-server", "env": { "EPTR_USERNAME": "your.email@example.com", "EPTR_PASSWORD": "yourpassword" } } } } ``` ### VS Code Configuration Enable MCP in VS Code settings: ```json { "chat.mcp.discovery.enabled": true } ``` ### Environment Variables | Variable | |----------| | `EPTR_USERNAME` | EPIAS platform username (email) | | `EPTR_PASSWORD` | EPIAS platform password | | `EPTR_TGT_PATH` | Custom path for TGT storage | ``` -------------------------------- ### Install eptr2 with All Extras using uv Source: https://github.com/tideseed/eptr2/blob/main/docs/getting-started/installation.md Install the package with all optional dependencies using the 'uv' package installer. ```bash uv pip install "eptr2[allextras]" ``` -------------------------------- ### Install eptr2 from Tutorials Directory (Development) Source: https://github.com/tideseed/eptr2/blob/main/tutorials/README.md Use this command to install the eptr2 library in development mode from the tutorials directory. ```bash cd tutorials pip install -e . ``` -------------------------------- ### Example .env.example Configuration Source: https://github.com/tideseed/eptr2/blob/main/docs/getting-started/authentication.md Example content for a .env.example file to document required environment variables without exposing actual credentials. ```env EPTR_USERNAME= EPTR_PASSWORD= ``` -------------------------------- ### Install Documentation Build Tools Source: https://github.com/tideseed/eptr2/blob/main/docs/reference/contributing.md Install the necessary packages for building the project documentation locally using MkDocs. ```bash pip install mkdocs-material mkdocstrings[python] ``` -------------------------------- ### Run MCP server example Source: https://github.com/tideseed/eptr2/blob/main/examples/README.md Execute the mcp_server_example.py script to view MCP server information. ```bash python examples/mcp_server_example.py ``` -------------------------------- ### Install MCP SDK Source: https://github.com/tideseed/eptr2/blob/main/TESTING_GUIDE.md Install the MCP SDK using pip. This is required for certain functionalities. ```bash pip install mcp ``` ```bash pip install "eptr2[mcp]" ``` -------------------------------- ### Install Basic eptr2 Source: https://github.com/tideseed/eptr2/blob/main/AGENTS.md Installs the eptr2 package with its minimal dependencies. ```bash # Basic installation (minimal dependencies) pip install eptr2 ``` -------------------------------- ### Run Example Scripts Locally Source: https://github.com/tideseed/eptr2/blob/main/PR_DESCRIPTION.md Execute this Python script to test the basic usage examples of the eptr2 library. ```bash # Run examples python examples/basic_usage.py ``` -------------------------------- ### Building eptr2 Documentation Locally Source: https://github.com/tideseed/eptr2/blob/main/docs/CONTRIBUTING.md Instructions for installing dependencies and serving the documentation locally. ```APIDOC ## Building Locally ### Install dependencies ```bash pip install "eptr2[docs]" # or pip install mkdocs-material mkdocstrings[python] mkdocs-autorefs ``` ### Serve locally ```bash mkdocs serve ``` Visit `http://localhost:8000` to preview the documentation. ### Build static site ```bash mkdocs build ``` The static site will be generated in the `site/` directory. ``` -------------------------------- ### Minimal Installation of eptr2 using uv Source: https://github.com/tideseed/eptr2/blob/main/docs/getting-started/installation.md Install only the core dependencies of the eptr2 package using the 'uv' package installer. ```bash uv pip install eptr2 ``` -------------------------------- ### Start MCP Server using Python Module Source: https://github.com/tideseed/eptr2/blob/main/TESTING_GUIDE.md Initiate the MCP server by running it as a Python module. This command starts the server and listens for incoming connections. ```bash python -m eptr2.mcp.server ``` -------------------------------- ### Basic Price Query Example Source: https://github.com/tideseed/eptr2/blob/main/docs/api/main.md Example demonstrating how to perform a basic Market Clearing Price (MCP) query for a specific date. ```python from eptr2 import EPTR2 eptr = EPTR2(use_dotenv=True, recycle_tgt=True) # Market Clearing Price mcp = eptr.call("mcp", start_date="2024-07-29", end_date="2024-07-29") print(mcp.head()) ``` -------------------------------- ### Get and display API documentation for a specific endpoint Source: https://github.com/tideseed/eptr2/blob/main/docs/api/util.md This example shows how to fetch and print documentation details for the 'rt-consumption' API endpoint, including its category, titles, description, and official URL. ```python from eptr2.mapping.help import get_help_d # Get documentation for consumption endpoint help_info = get_help_d("rt-consumption") print(f"Category: {help_info['category']}") print(f"Title (TR): {help_info['title']['tr']}") print(f"Title (EN): {help_info['title']['en']}") print(f"Description: {help_info['desc']['en']}") ``` -------------------------------- ### Install uv package manager Source: https://github.com/tideseed/eptr2/blob/main/CLAUDE_SETUP.md Install uv, a recommended tool for faster and more reliable Python execution. ```bash pip install uv ``` -------------------------------- ### Set Up Environment Variables Source: https://github.com/tideseed/eptr2/blob/main/docs/reference/contributing.md Copy the example environment file and edit it with your EPIAS credentials. This file is used to configure API access. ```bash cp .env.example .env # Edit .env with your EPIAS credentials ``` -------------------------------- ### Example .gitignore Configuration Source: https://github.com/tideseed/eptr2/blob/main/docs/getting-started/authentication.md Example content for a .gitignore file to prevent sensitive credentials and TGT files from being committed to version control. ```gitignore .env .eptr2-tgt ``` -------------------------------- ### View Testing Guide Source: https://github.com/tideseed/eptr2/blob/main/PR_DESCRIPTION.md Display the content of the testing guide to understand how to test the eptr2 library and its MCP server. ```bash # View testing guide cat TESTING_GUIDE.md ``` -------------------------------- ### Install Development Dependencies Source: https://github.com/tideseed/eptr2/blob/main/docs/reference/contributing.md Install the project's development dependencies, including optional extras, using pip. This command installs the package in editable mode. ```bash pip install -e ".[dev,allextras]" ``` -------------------------------- ### MCP Server Setup and Configuration Source: https://github.com/tideseed/eptr2/blob/main/docs/api/mcp.md Instructions on how to run the MCP server, either via the command line or programmatically, and how to configure it. ```APIDOC ## MCP Server Setup and Configuration ### Overview The MCP server enables AI assistants like Claude to directly query Turkish electricity market data through a standardized protocol. ### Quick Start Run the server from the command line: ```bash eptr2-mcp-server ``` Or programmatically using Python: ```python from eptr2.mcp import run_mcp_server import asyncio asyncio.run(run_mcp_server(use_dotenv=True, recycle_tgt=True)) ``` ### create_mcp_server Function Creates and configures the FastMCP server instance. ```python from eptr2.mcp import create_mcp_server server = create_mcp_server( use_dotenv=True, recycle_tgt=True, dotenv_path=".env", tgt_path=".", ) # Run when ready server.run() ``` **Parameters:** | Parameter | Type | Default | Description | |-----------|------|---------|-------------| | `use_dotenv` | `bool` | `True` | Load credentials from `.env` file | | `recycle_tgt` | `bool` | `True` | Reuse authentication tickets | | `dotenv_path` | `str` | `".env"` | Path to `.env` file | | `tgt_path` | `str` | `"."` | Directory for `.eptr2-tgt` cache | ### run_mcp_server Function Main entry point for the MCP server. ```python from eptr2.mcp import run_mcp_server import asyncio asyncio.run(run_mcp_server( use_dotenv=True, # Load credentials from .env recycle_tgt=True, # Reuse TGT tickets dotenv_path=".env", # Path to .env file )) ``` **Parameters:** | Parameter | Type | Default | Description | |-----------|------|---------|-------------| | `use_dotenv` | `bool` | `True` | Load credentials from `.env` file | | `recycle_tgt` | `bool` | `True` | Reuse authentication tickets | | `dotenv_path` | `str` | `".env"` | Path to `.env` file | | `tgt_path` | `str` | `"."` | Directory for `.eptr2-tgt` cache | ``` -------------------------------- ### Install eptr2 from Source Source: https://github.com/tideseed/eptr2/blob/main/TESTING_GUIDE.md Use this command to install the eptr2 library in development mode from its source code, including all extras. This is recommended for testing purposes. ```bash git clone https://github.com/Tideseed/eptr2.git cd eptr2 git checkout agent-1 # OR git checkout copilot/prepare-library-for-agentic-ai pip install -e ".[allextras,mcp,dev]" ``` -------------------------------- ### Install eptr2 with MCP Support and Run Server Source: https://github.com/tideseed/eptr2/blob/main/CHANGELOG_MCP.md Install the eptr2 package with optional MCP support and then run the MCP server using the provided CLI command. ```bash # Install with MCP support pip install "eptr2[allextras,mcp]" # Run the server eptr2-mcp-server ``` -------------------------------- ### Run MCP Server Source: https://github.com/tideseed/eptr2/blob/main/src/eptr2/mcp/README.md Starts the Market Clearing Price (MCP) server. Ensure .env file is configured for authentication. ```python from eptr2.mcp import run_mcp_server import asyncio async def test(): # This will start the server await run_mcp_server(use_dotenv=True, recycle_tgt=True) if __name__ == "__main__": asyncio.run(test()) ``` -------------------------------- ### Google-Style Docstring Example Source: https://github.com/tideseed/eptr2/blob/main/docs/reference/contributing.md An example of a Python function using Google-style docstrings, including descriptions for arguments, return values, raised exceptions, and examples. ```python def function(param1: str, param2: int) -> pd.DataFrame: """Short description. Longer description if needed. Args: param1: Description of param1. param2: Description of param2. Returns: Description of return value. Raises: ValueError: When something is wrong. Example: >>> result = function("test", 123) >>> print(result) """ ``` -------------------------------- ### Run MCP Server from Command Line Source: https://github.com/tideseed/eptr2/blob/main/AGENTS.md Provides command-line options to start the MCP server. 'uv' is recommended for faster startup. ```bash # Using uv (recommended) uv run --extra mcp eptr2-mcp-server ``` ```bash # Using standard Python python -m eptr2.mcp.server ``` -------------------------------- ### Install eptr2 with All Extras using pipx Source: https://github.com/tideseed/eptr2/blob/main/docs/getting-started/installation.md Install the package with all optional dependencies using 'pipx' for isolated environments. ```bash pipx install "eptr2[allextras]" ``` -------------------------------- ### Install EPTR2 with Extras Source: https://context7.com/tideseed/eptr2/llms.txt Install the package with all extras for full functionality including pandas and MCP server support. ```bash pip install "eptr2[allextras]" ``` ```bash pip install eptr2 ``` -------------------------------- ### Development Installation of eptr2 Source: https://github.com/tideseed/eptr2/blob/main/docs/getting-started/installation.md Clone the repository and install eptr2 in editable mode with development and all extra dependencies. ```bash git clone https://github.com/Tideseed/eptr2.git cd eptr2 pip install -e ".[dev,allextras]" ``` -------------------------------- ### Verbose Output Example Source: https://github.com/tideseed/eptr2/blob/main/docs/api/composite.md Shows how to enable verbose output for `get_hourly_consumption_and_forecast_data` to track progress. This is useful for monitoring long-running data fetches. ```python df = get_hourly_consumption_and_forecast_data( start_date="2024-07-01", end_date="2024-07-31", verbose=True ) ``` -------------------------------- ### Basic Price Query Example Source: https://github.com/tideseed/eptr2/blob/main/docs/api/main.md Example of how to perform a basic Market Clearing Price (MCP) query. ```APIDOC ## Basic Price Query ```python from eptr2 import EPTR2 eptr = EPTR2(use_dotenv=True, recycle_tgt=True) # Market Clearing Price mcp = eptr.call("mcp", start_date="2024-07-29", end_date="2024-07-29") print(mcp.head()) ``` ``` -------------------------------- ### Minimal Installation of eptr2 using pip Source: https://github.com/tideseed/eptr2/blob/main/docs/getting-started/installation.md Install only the core dependencies of the eptr2 package. ```bash pip install eptr2 ``` -------------------------------- ### Custom Skill File Structure Source: https://github.com/tideseed/eptr2/blob/main/docs/ai-integration/agent-skills.md Example structure for a custom skill's SKILL.md file, including description, triggers, knowledge base, and example queries with expected behavior. ```markdown # My Custom Skill ## Description This skill helps with [specific use case]. ## Triggers - keyword1 - keyword2 ## Knowledge [Domain-specific information] ## Examples - "Example query 1" → [Expected behavior] - "Example query 2" → [Expected behavior] ``` -------------------------------- ### Example .env file content Source: https://github.com/tideseed/eptr2/blob/main/README.md A sample .env file format for storing EPIAS username and password. Place this file in the same directory as your script. ```dotenv EPTR_USERNAME=youremail@something.com EPTR_PASSWORD=yourpassword ``` -------------------------------- ### Run basic usage examples Source: https://github.com/tideseed/eptr2/blob/main/AI_AGENT_INTEGRATION_SUMMARY.md Execute the basic usage Python script to see examples of common eptr2 library functions. This script covers price queries, data source queries, composite functions, API discovery, generation data, and error handling. ```bash python examples/basic_usage.py ``` -------------------------------- ### Calculate Imbalance Cost Example Source: https://github.com/tideseed/eptr2/blob/main/docs/tutorials/calculator.md Demonstrates a simple calculation for energy imbalance cost based on a deficit and a given price. This example illustrates the core logic for cost estimation. ```python # Scenario: 100 MWh deficit on 2024-07-29 at 14:00 # Positive imbalance price: 1500 TL/MWh deficit = 100 # MWh price = 1500 # TL/MWh cost = deficit * price print(f"Imbalance cost: {cost:,.2f} TL") # 150,000.00 TL ``` -------------------------------- ### Multiple Queries Example Source: https://github.com/tideseed/eptr2/blob/main/docs/api/main.md Demonstrates making multiple API calls using the same EPTR2 instance. ```APIDOC ## Multiple Queries ```python # Reuse instance for multiple queries eptr = EPTR2(use_dotenv=True, recycle_tgt=True) mcp = eptr.call("mcp", start_date="2024-07-01", end_date="2024-07-31") smp = eptr.call("smp", start_date="2024-07-01", end_date="2024-07-31") consumption = eptr.call("rt-cons", start_date="2024-07-01", end_date="2024-07-31") ``` ``` -------------------------------- ### Install eptr2 for direct library usage Source: https://github.com/tideseed/eptr2/blob/main/AI_AGENT_INTEGRATION_SUMMARY.md Install the eptr2 library with all extras for direct programmatic usage. This command does not include MCP server specific dependencies. ```bash pip install "eptr2[allextras]" ``` -------------------------------- ### Example: Basic Usage of eptr2 Source: https://github.com/tideseed/eptr2/blob/main/PR_DESCRIPTION.md This Python script demonstrates fundamental examples of using the eptr2 library. It covers various functionalities for querying electricity market data. ```python import asyncio import os from eptr2.mcp.client import MCPClient async def main(): # Load credentials from environment variables username = os.getenv("EPTR_USERNAME") password = os.getenv("EPTR_PASSWORD") if not username or not password: print("Please set EPTR_USERNAME and EPTR_PASSWORD environment variables.") return # Initialize MCP client client = MCPClient(username=username, password=password) try: # Example 1: Get day-ahead market clearing prices print("\n--- Getting Day-Ahead Market Clearing Prices ---") dscp = await client.get_market_clearing_price() print(f"Day-ahead clearing price: {dscp}") # Example 2: Get system marginal prices print("\n--- Getting System Marginal Prices ---") smp = await client.get_system_marginal_price() print(f"System marginal price: {smp}") # Example 3: Get real-time consumption data print("\n--- Getting Real-Time Consumption Data ---") rtc = await client.get_real_time_consumption() print(f"Real-time consumption: {rtc}") # Example 4: Get real-time generation by resource type print("\n--- Getting Real-Time Generation by Resource Type ---") rtg = await client.get_real_time_generation() print(f"Real-time generation: {rtg}") # Example 5: Get demand forecast print("\n--- Getting Demand Forecast ---") df = await client.get_demand_forecast() print(f"Demand forecast: {df}") # Example 6: Get imbalance price print("\n--- Getting Imbalance Price ---") ip = await client.get_imbalance_price() print(f"Imbalance price: {ip}") except Exception as e: print(f"An error occurred: {e}") finally: # Close the client connection await client.close() if __name__ == "__main__": asyncio.run(main()) ``` -------------------------------- ### Start EPTR2 MCP Server from Command Line Source: https://context7.com/tideseed/eptr2/llms.txt Starts the EPTR2 MCP server from the command line. Requires setting environment variables for username and password or using a .env file. The command `eptr2-mcp-server` initiates the server. ```bash # Set environment variables or use .env file export EPTR_USERNAME="your.email@example.com" export EPTR_PASSWORD="your_password" # Start MCP server eptr2-mcp-server ``` -------------------------------- ### Install eptr2 with Extras Source: https://github.com/tideseed/eptr2/blob/main/AGENTS.md Installs the eptr2 package with all optional dependencies, including support for Claude Desktop integration, data analysis with pandas, and the demo app. ```bash # Recommended: Install with all extras (includes MCP support) pip install "eptr2[allextras]" ``` -------------------------------- ### Install EPTR2 MCP Server (Manual) Source: https://github.com/tideseed/eptr2/blob/main/src/eptr2/mcp/README.md Manually install the EPTR2 MCP server and its dependency, fastmcp, using pip. ```bash pip install eptr2 fastmcp ``` -------------------------------- ### Install Documentation Dependencies Source: https://github.com/tideseed/eptr2/blob/main/docs/CONTRIBUTING.md Install the necessary Python packages for building MkDocs documentation. This includes the core eptr2 package with docs extras or individual packages like mkdocs-material and mkdocstrings. ```bash pip install "eptr2[docs]" # or pip install mkdocs-material mkdocstrings[python] mkdocs-autorefs ``` -------------------------------- ### Get Imbalance Prices Data Source: https://github.com/tideseed/eptr2/blob/main/QUICK_REFERENCE.md Fetch imbalance prices for a specified month using the `mcp-smp-imb` call key. Both start and end dates are inclusive. ```python # Imbalance prices imb = eptr.call("mcp-smp-imb", start_date="2024-07-01", end_date="2024-07-31") ``` -------------------------------- ### Get Default DataFrame Return Type Source: https://github.com/tideseed/eptr2/blob/main/docs/getting-started/quickstart.md By default, the `call` method returns data as a pandas DataFrame if the pandas library is installed. This snippet demonstrates how to check the type. ```python df = eptr.call("mcp", start_date="2024-07-29", end_date="2024-07-29") print(type(df)) # ``` -------------------------------- ### Get System Marginal Price (SMP/SMF) Data Source: https://github.com/tideseed/eptr2/blob/main/docs/api/mcp.md Fetch System Marginal Prices by providing a start and end date. This tool is useful for understanding system-wide price dynamics. ```json { "name": "get_system_marginal_price", "arguments": { "start_date": "2024-07-29", "end_date": "2024-07-29" } } ``` -------------------------------- ### Get Balancing Power Market (BPM) Data Source: https://github.com/tideseed/eptr2/blob/main/docs/user-guide/composite-functions.md Retrieves data from the Balancing Power Market (BPM) for a specific date. Requires start and end dates and an optional EPTR2 instance. ```python from eptr2.composite import get_bpm_data bpm = get_bpm_data( start_date="2024-07-29", end_date="2024-07-29", eptr=eptr ) ``` -------------------------------- ### Get Market Management System (MMS) Data Source: https://github.com/tideseed/eptr2/blob/main/docs/user-guide/composite-functions.md Fetches data from the Market Management System (MMS) for a specified date. Requires start and end dates and an optional EPTR2 instance. ```python from eptr2.composite import get_mms_data mms = get_mms_data( start_date="2024-07-29", end_date="2024-07-29", eptr=eptr ) ``` -------------------------------- ### Get Organization Periodic Data Source: https://github.com/tideseed/eptr2/blob/main/docs/user-guide/composite-functions.md Fetches periodic data for a specific organization (org ID) over a given date range. Requires start date, end date, organization ID, and an optional EPTR2 instance. ```python from eptr2.composite import get_periodic_org_data org_data = get_periodic_org_data( start_date="2024-07-01", end_date="2024-07-31", org_id=123, eptr=eptr ) ``` -------------------------------- ### Complete Analysis Pipeline Example Source: https://github.com/tideseed/eptr2/blob/main/docs/api/composite.md Demonstrates a complete analysis pipeline by fetching consumption and price data, merging them, and calculating total costs. Requires EPTR2 initialization. ```python from eptr2 import EPTR2 from eptr2.composite import ( get_hourly_consumption_and_forecast_data, get_hourly_price_and_cost_data ) import pandas as pd # Initialize once eptr = EPTR2(use_dotenv=True, recycle_tgt=True) # Get consumption data consumption = get_hourly_consumption_and_forecast_data( start_date="2024-07-01", end_date="2024-07-31", eptr=eptr, verbose=True ) # Get price data prices = get_hourly_price_and_cost_data( start_date="2024-07-01", end_date="2024-07-31", eptr=eptr ) # Merge for analysis analysis = pd.merge(consumption, prices, on='dt') # Calculate costs analysis['total_cost'] = analysis['consumption'] * analysis['mcp'] print(f"Total cost: {analysis['total_cost'].sum():,.2f} TL") ``` -------------------------------- ### Get Intraday Market (IDM) Log Data Source: https://github.com/tideseed/eptr2/blob/main/docs/user-guide/composite-functions.md Retrieves data from the Intraday Market (IDM) log for a specific date. Requires start and end dates (typically the same for a single day) and an optional EPTR2 instance. ```python from eptr2.composite import get_idm_log_data idm_log = get_idm_log_data( start_date="2024-07-29", end_date="2024-07-29", eptr=eptr ) ``` -------------------------------- ### Run Calculator Tutorial App Source: https://github.com/tideseed/eptr2/blob/main/README.md Launch the calculator tutorial app to estimate imbalance and KÜPST costs. This feature requires specifying the date, hour, and custom actual/forecast values. Provide your username and password for authentication. ```python from eptr2.tutorials import run_calc_app run_calc_app(username="YOUR_USERNAME",password="YOUR_PASSWORD") ``` -------------------------------- ### Serve MkDocs Documentation Locally Source: https://github.com/tideseed/eptr2/blob/main/docs/CONTRIBUTING.md Build and serve the MkDocs documentation locally to preview changes. Visit http://localhost:8000 to view the site. ```bash mkdocs serve ``` -------------------------------- ### Custom Timeout Example Source: https://github.com/tideseed/eptr2/blob/main/docs/api/main.md Example of setting a custom timeout for API requests. ```APIDOC ## With Custom Timeout ```python df = eptr.call( "mcp", start_date="2024-07-01", end_date="2024-07-31", request_kwargs={"timeout": 30} ) ``` ``` -------------------------------- ### Verify eptr2 installation Source: https://github.com/tideseed/eptr2/blob/main/docs/ai-integration/claude-desktop.md Check if the eptr2 package is installed in the current Python environment. ```bash pip show eptr2 ``` -------------------------------- ### EPTR2 Initialization and Basic Usage Source: https://github.com/tideseed/eptr2/blob/main/AGENTS.md Demonstrates how to initialize the EPTR2 client using environment variables or direct credentials and make a basic API call. ```APIDOC ## EPTR2 Initialization and Basic Usage ### Description Initialize the EPTR2 client and make a basic API call to retrieve market data. ### Authentication Methods 1. **Environment Variables (Recommended)**: Set `EPTR_USERNAME` and `EPTR_PASSWORD` in a `.env` file. ```python from eptr2 import EPTR2 eptr = EPTR2(use_dotenv=True, recycle_tgt=True) ``` 2. **Direct Credentials**: Provide username and password directly. ```python from eptr2 import EPTR2 eptr = EPTR2(username="email@example.com", password="password") ``` ### Basic API Call Call any available endpoint. The example below retrieves Market Clearing Price (MCP) data. ```python from eptr2 import EPTR2 # Initialize with auto-auth (using environment variables) eptr = EPTR2(use_dotenv=True, recycle_tgt=True) # Call the 'mcp' endpoint for a specific date result = eptr.call("mcp", start_date="2024-07-29", end_date="2024-07-29") # The result is typically a pandas DataFrame if pandas is installed print(result) ``` ### Common Parameters - `start_date` (string): Start date in `YYYY-MM-DD` format. - `end_date` (string): End date in `YYYY-MM-DD` format. - `postprocess` (boolean): Set to `False` to return raw JSON instead of a DataFrame (default is `True`). ### Example API Calls - **Prices**: `eptr.call("mcp", ...)` or `eptr.call("ptf", ...)` - **Consumption**: `eptr.call("rt-cons", ...)` - **Generation**: `eptr.call("rt-gen", ...)` - **Load Plan**: `eptr.call("load-plan", ...)` ``` -------------------------------- ### Query with Organization ID Example Source: https://github.com/tideseed/eptr2/blob/main/docs/api/main.md Example of making a query that requires an organization ID. ```APIDOC ## With Organization ID ```python df = eptr.call( "bilateral-contracts-org", start_date="2024-07-29", end_date="2024-07-29", org_id=123 ) ``` ``` -------------------------------- ### Complete Data Analysis Example Source: https://github.com/tideseed/eptr2/blob/main/AGENTS.md Performs a comprehensive analysis by fetching hourly consumption forecasts and pricing data, then merging them. Requires .env for credentials and `recycle_tgt=True` for efficient ticket management. ```python from eptr2 import EPTR2 from eptr2.composite import ( get_hourly_consumption_and_forecast_data, get_hourly_price_and_cost_data ) # Initialize eptr = EPTR2(use_dotenv=True, recycle_tgt=True) # Get consumption and forecast consumption_df = get_hourly_consumption_and_forecast_data( eptr, start_date="2024-07-01", end_date="2024-07-31" ) # Get pricing data price_df = get_hourly_price_and_cost_data( eptr, start_date="2024-07-01", end_date="2024-07-31" ) # Merge for analysis import pandas as pd analysis = pd.merge( consumption_df, price_df, on=['date', 'hour'], how='inner' ) ``` -------------------------------- ### Install eptr2 with DataFrame Support Source: https://github.com/tideseed/eptr2/blob/main/docs/getting-started/installation.md Install the package with the 'dataframe' extra to include pandas support. ```bash pip install "eptr2[dataframe]" ``` -------------------------------- ### Install eptr2 with MCP Agent Features Source: https://github.com/tideseed/eptr2/blob/main/docs/getting-started/installation.md Install the package with the 'mcp' extra for AI agent integration. ```bash pip install "eptr2[mcp]" ``` -------------------------------- ### Create and Configure MCP Server Instance Source: https://github.com/tideseed/eptr2/blob/main/docs/api/mcp.md Instantiate the FastMCP server using `create_mcp_server`. This allows for more granular control over server configuration, including environment loading and ticket recycling. ```python from eptr2.mcp import create_mcp_server server = create_mcp_server( use_dotenv=True, recycle_tgt=True, dotenv_path=".env", tgt_path=".", ) # Run when ready server.run() ``` -------------------------------- ### Raw JSON Response Example Source: https://github.com/tideseed/eptr2/blob/main/docs/api/main.md Example of retrieving the raw JSON response instead of a processed DataFrame. ```APIDOC ## Raw JSON Response ```python raw = eptr.call( "mcp", start_date="2024-07-29", end_date="2024-07-29", postprocess=False ) print(type(raw)) # dict ``` ``` -------------------------------- ### Using Custom EPTR2 Instance Source: https://github.com/tideseed/eptr2/blob/main/docs/api/composite.md Illustrates how to initialize and use a custom EPTR2 instance with specific configurations, such as a custom target path. This allows for more control over data handling and storage. ```python from eptr2 import EPTR2 from eptr2.composite import get_hourly_consumption_and_forecast_data # Custom configuration eptr = EPTR2( use_dotenv=True, recycle_tgt=True, tgt_path="/custom/path" ) df = get_hourly_consumption_and_forecast_data( start_date="2024-07-01", end_date="2024-07-31", eptr=eptr ) ``` -------------------------------- ### Create and Activate Virtual Environment Source: https://github.com/tideseed/eptr2/blob/main/docs/reference/contributing.md Create a Python virtual environment for the project and activate it. The activation command differs between Linux/macOS and Windows. ```bash python -m venv .venv source .venv/bin/activate # Linux/macOS # or .venv\Scripts\activate # Windows ``` -------------------------------- ### Run eptr2 Demo Apps from Command Line Source: https://github.com/tideseed/eptr2/blob/main/tutorials/README.md Launch the different eptr2 demo applications from your terminal. ```bash # Main composite functions demo eptr2demo # Basic API demo eptr-demo # Imbalance calculator demo eptr2-calc ``` -------------------------------- ### Example: MCP Server Usage Source: https://github.com/tideseed/eptr2/blob/main/PR_DESCRIPTION.md This Python script demonstrates how to interact with the eptr2 MCP server. It shows how to initialize the client and call various tools to retrieve electricity market data. ```python import asyncio import os from eptr2.mcp.client import MCPClient async def main(): # Load credentials from environment variables username = os.getenv("EPTR_USERNAME") password = os.getenv("EPTR_PASSWORD") if not username or not password: print("Please set EPTR_USERNAME and EPTR_PASSWORD environment variables.") return # Initialize MCP client client = MCPClient(username=username, password=password) try: # Example 7: Get available eptr2 calls (API endpoints) print("\n--- Getting Available eptr2 Calls ---") available_calls = await client.get_available_eptr2_calls() print(f"Number of available calls: {len(available_calls)}") # print(f"Available calls: {available_calls}") # Uncomment to see all calls # Example 8: Generic API call to a specific endpoint (e.g., get_hourly_consumption_and_forecast) print("\n--- Making a Generic API Call ---") # Note: The exact parameters might vary based on the endpoint. # This is a simplified example. generic_call_result = await client.call_eptr2_api( "get_hourly_consumption_and_forecast", params={"date": "2023-10-26"} # Example parameter, adjust as needed ) print(f"Generic API call result (first 100 chars): {str(generic_call_result)[:100]}...") # Example 9: Get composite consumption and forecast data print("\n--- Getting Hourly Consumption and Forecast ---") hcf = await client.get_hourly_consumption_and_forecast() print(f"Hourly consumption and forecast (first 100 chars): {str(hcf)[:100]}...") # Example 10: Get comprehensive price and cost data print("\n--- Getting Price and Cost Data ---") pcd = await client.get_price_and_cost_data() print(f"Price and cost data (first 100 chars): {str(pcd)[:100]}...") except Exception as e: print(f"An error occurred: {e}") finally: # Close the client connection await client.close() if __name__ == "__main__": asyncio.run(main()) ``` -------------------------------- ### Install Eptr2 Package Source: https://github.com/tideseed/eptr2/blob/main/TESTING_GUIDE.md Install the Eptr2 package, including extras for MCP support. Use editable mode for development. ```bash pip install -e ".[allextras,mcp]" ``` ```bash pip install eptr2 ``` -------------------------------- ### Verify eptr2 Installation Source: https://github.com/tideseed/eptr2/blob/main/docs/getting-started/installation.md Run this Python code after installation to check if the eptr2 package is accessible and print its version or a confirmation message. ```python import eptr2 print(eptr2.__version__ if hasattr(eptr2, '__version__') else "Installed!") ``` -------------------------------- ### Initialize EPTR2 with Environment Variables Source: https://context7.com/tideseed/eptr2/llms.txt Initialize the EPTR2 client using environment variables for credentials and enable TGT recycling for efficiency. This is the recommended approach for managing credentials. ```python from eptr2 import EPTR2 # Create .env file with credentials: # EPTR_USERNAME=your.email@example.com # EPTR_PASSWORD=your_password # Initialize with environment file (recommended approach) eptr = EPTR2( use_dotenv=True, # Default: True recycle_tgt=True, # Default: True - reuses TGT across sessions dotenv_path=".env", # Default: ".env" tgt_path="." # Directory to store TGT file ) # Make API calls - TGT is automatically managed df = eptr.call("mcp", start_date="2025-01-01", end_date="2025-01-31") # Export TGT info for inspection tgt_info = eptr.export_tgt_info() print(f"TGT expires at: {tgt_info['tgt_exp_dt']}") ``` -------------------------------- ### Initialize EPTR2 with Environment File Source: https://github.com/tideseed/eptr2/blob/main/docs/getting-started/authentication.md Initialize the EPTR2 client using credentials from a .env file. Ensure the .env file is present in the project directory. TGT recycling is enabled by default. ```python from eptr2 import EPTR2 eptr = EPTR2(use_dotenv=True, recycle_tgt=True) ``` -------------------------------- ### Get all API endpoint paths Source: https://github.com/tideseed/eptr2/blob/main/docs/api/util.md Retrieves a mapping of all available API endpoint paths. Set `just_call_keys=True` to get only the endpoint names. ```python from eptr2.mapping import get_path_map # Get all path keys paths = get_path_map(just_call_keys=True) print(len(paths)) # 213+ ``` -------------------------------- ### Custom MCP Integration with Client Library Source: https://github.com/tideseed/eptr2/blob/main/docs/ai-integration/mcp-server.md Example of using the MCP client library to connect to the server, list tools, and call a tool programmatically. ```python import asyncio from mcp import ClientSession, StdioServerParameters from mcp.client.stdio import stdio_client async def main(): server_params = StdioServerParameters( command="eptr2-mcp-server" ) async with stdio_client(server_params) as (read, write): async with ClientSession(read, write) as session: await session.initialize() # List available tools tools = await session.list_tools() print(tools) # Call a tool result = await session.call_tool( "get_market_clearing_price", {"start_date": "2024-07-29", "end_date": "2024-07-29"} ) print(result) asyncio.run(main()) ``` -------------------------------- ### Quick Start with eptr2 Source: https://github.com/tideseed/eptr2/blob/main/docs/api/eptr2.md Initialize the EPTR2 class and call the 'mcp' function to retrieve market clearing prices. Ensure environment variables are set for authentication if use_dotenv is True. ```python from eptr2 import EPTR2 eptr = EPTR2(use_dotenv=True, recycle_tgt=True) df = eptr.call("mcp", start_date="2024-07-29", end_date="2024-07-29") ``` -------------------------------- ### List all API endpoints and find price-related ones Source: https://github.com/tideseed/eptr2/blob/main/docs/api/util.md This example demonstrates how to retrieve all available API endpoint keys and then filter them to find endpoints related to 'price'. ```python from eptr2.mapping import get_path_map, alias_to_path # List all endpoints all_endpoints = get_path_map(just_call_keys=True) # Find price-related endpoints price_endpoints = [e for e in all_endpoints if 'price' in e.lower()] print(price_endpoints) # Check if alias exists canonical = alias_to_path("ptf") print(f"'ptf' maps to '{canonical}'") ``` -------------------------------- ### Run eptr2 Demo App Source: https://github.com/tideseed/eptr2/blob/main/CHANGELOG.md Launches the eptr2 demo application. Replace YOUR_USERNAME and YOUR_PASSWORD with your actual credentials. ```python from eptr2.tutorials import run_demo_app run_demo_app(username="YOUR_USERNAME",password="YOUR_PASSWORD") ``` -------------------------------- ### Install eptr2 with MCP support Source: https://github.com/tideseed/eptr2/blob/main/AI_AGENT_INTEGRATION_SUMMARY.md Install the eptr2 library with all extras and MCP support using pip. This command ensures all necessary dependencies for MCP server functionality are included. ```bash pip install "eptr2[allextras,mcp]" ``` -------------------------------- ### EPTR2 Class Initialization Source: https://github.com/tideseed/eptr2/blob/main/docs/api/main.md Demonstrates how to initialize the EPTR2 class using environment variables or direct credentials. ```APIDOC ## EPTR2 Class Initialization ### Description Initialize the EPTR2 class for interacting with the EPIAS Transparency Platform API. Credentials can be loaded from a `.env` file or provided directly. ### Constructor Parameters | Parameter | Type | Default | Description | |-----------|------|---------|-------------| | `username` | `str` | `None` | EPIAS platform username (email) | | `password` | `str` | `None` | EPIAS platform password | | `recycle_tgt` | `bool` | `True` | Reuse authentication tickets | | `use_dotenv` | `bool` | `True` | Load credentials from `.env` file | | `dotenv_path` | `str` | `".env"` | Path to the `.env` file | | `ssl_verify` | `bool` | `True` | Verify SSL certificates | | `postprocess` | `bool` | `True` | Return DataFrame instead of raw response | | `get_raw_response` | `bool` | `False` | Return raw HTTP response | ### Request Example ```python from eptr2 import EPTR2 # Using .env file for credentials eptr = EPTR2(use_dotenv=True, recycle_tgt=True) # Direct credentials eptr = EPTR2(username="email@example.com", password="password") ``` ``` -------------------------------- ### Generate Placeholder Logo with Pillow Source: https://github.com/tideseed/eptr2/blob/main/docs/assets/README.md Use this Python script with the Pillow library to create a simple 'logo.png' placeholder for your documentation header. Ensure Pillow is installed (`pip install Pillow`). ```python from PIL import Image, ImageDraw, ImageFont img = Image.new('RGB', (64, 64), color='#4F46E5') d = ImageDraw.Draw(img) d.text((12, 16), "E2", fill='white') img.save('logo.png') ``` -------------------------------- ### Initialize eptr2 Client and Make First API Call Source: https://github.com/tideseed/eptr2/blob/main/docs/getting-started/quickstart.md Initialize the eptr2 client using environment variables for authentication and then make a call to fetch Market Clearing Price (MCP/PTF) data for a specific date. Ensure pandas is installed for DataFrame output. ```python from eptr2 import EPTR2 # Initialize the client eptr = EPTR2(use_dotenv=True, recycle_tgt=True) # Get Market Clearing Price (MCP/PTF) df = eptr.call("mcp", start_date="2024-07-29", end_date="2024-07-29") print(df) ``` -------------------------------- ### Run eptr2 Demo Directly with uv Source: https://github.com/tideseed/eptr2/blob/main/tutorials/README.md Execute the eptr2 demo application directly using the 'uv run' command. ```bash cd tutorials uv run eptr2demo ``` -------------------------------- ### Error Handling Example Source: https://github.com/tideseed/eptr2/blob/main/docs/api/main.md Demonstrates basic error handling when making API calls. ```APIDOC ## Error Handling ```python from eptr2 import EPTR2 eptr = EPTR2(use_dotenv=True) try: df = eptr.call("mcp", start_date="2024-07-29", end_date="2024-07-29") except Exception as e: print(f"Error: {e}") ``` ``` -------------------------------- ### Initialize EPTR2 Client Source: https://github.com/tideseed/eptr2/blob/main/QUICK_REFERENCE.md Instantiate the EPTR2 client, optionally using environment variables for authentication and enabling target recycling. ```python from eptr2 import EPTR2 eptr = EPTR2(use_dotenv=True, recycle_tgt=True) ``` -------------------------------- ### Get Count of Available Calls Source: https://github.com/tideseed/eptr2/blob/main/docs/api/main.md Obtain the total number of available API endpoints. ```python count = eptr.get_number_of_calls() print(f"{count} calls available") ``` -------------------------------- ### Initialize EPTR2 with Direct Credentials Source: https://github.com/tideseed/eptr2/blob/main/docs/getting-started/authentication.md Initialize the EPTR2 client by passing username and password directly. This method is useful for quick testing but not recommended for production due to security risks. ```python from eptr2 import EPTR2 eptr = EPTR2( username="your.email@example.com", password="yourpassword" ) ``` -------------------------------- ### Discovering All Calls API Source: https://github.com/tideseed/eptr2/blob/main/docs/user-guide/api-calls.md APIs to discover available calls and get documentation for specific calls. ```APIDOC ## Discovering All Calls ### Description APIs to discover available calls and get documentation for specific calls. ### Method GET ### Endpoint /api/v1/calls ### Parameters #### Query Parameters - **action** (string) - Required - `list_all` or `get_help` - **call_key** (string) - Optional - Required if action is `get_help` ### Request Example ```json { "action": "list_all" } ``` ### Response #### Success Response (200) - **data** (array) - List of available call keys or documentation details #### Response Example ```json { "data": [ "mcp", "smp", "rt-cons" ] } ``` ``` -------------------------------- ### Run MCP Server with Detailed Parameters Source: https://github.com/tideseed/eptr2/blob/main/docs/api/mcp.md Execute the `run_mcp_server` function with explicit parameters for loading environment variables and managing authentication tickets. Comments indicate the purpose of each parameter. ```python from eptr2.mcp import run_mcp_server import asyncio asyncio.run(run_mcp_server( use_dotenv=True, # Load credentials from .env recycle_tgt=True, # Reuse TGT tickets dotenv_path=".env", # Path to .env file )) ```