### Install Frequenz SDK Source: https://github.com/frequenz-floss/frequenz-sdk-python/blob/v1.x.x/README.md Install the Frequenz SDK using pip within an activated virtual environment. ```sh python3 -m pip install frequenz-sdk ``` -------------------------------- ### Install MkDocs Dependencies for Documentation Source: https://github.com/frequenz-floss/frequenz-sdk-python/blob/v1.x.x/CONTRIBUTING.md Install the necessary dependencies to build the project's documentation using MkDocs. ```sh python -m pip install -e .[dev-mkdocs] ``` -------------------------------- ### Install Project for Local Development Source: https://github.com/frequenz-floss/frequenz-sdk-python/blob/v1.x.x/CONTRIBUTING.md Install the project in editable mode to develop locally. This command also installs all necessary dependencies. ```sh python -m pip install -e . ``` -------------------------------- ### Serve Project Documentation Locally Source: https://github.com/frequenz-floss/frequenz-sdk-python/blob/v1.x.x/CONTRIBUTING.md Serve the project documentation locally without building it first. Changes to files will update the site live if installed with '-e'. ```sh mkdocs serve ``` -------------------------------- ### Install Nox Dependencies and Run Nox Source: https://github.com/frequenz-floss/frequenz-sdk-python/blob/v1.x.x/CONTRIBUTING.md Install dependencies required for Nox and then run Nox to manage virtual environments for tests and checks. ```sh python -m pip install .[dev-noxfile] nox ``` -------------------------------- ### Setup Virtual Environment with direnv Source: https://github.com/frequenz-floss/frequenz-sdk-python/blob/v1.x.x/docs/index.md Automate virtual environment creation and activation using direnv. This simplifies environment management, especially when navigating between projects. ```sh sudo apt install direnv # if you use Debian/Ubuntu mkdir my-sdk-project cd my-sdk-project echo "layout python python3" > .envrc direnv allow ``` -------------------------------- ### Install Project with Development Dependencies Source: https://github.com/frequenz-floss/frequenz-sdk-python/blob/v1.x.x/CONTRIBUTING.md Install the project in editable mode along with all development dependencies like mypy, pylint, and pytest. ```sh python -m pip install -e .[dev] ``` -------------------------------- ### Full Frequenz SDK Application Example Source: https://github.com/frequenz-floss/frequenz-sdk-python/blob/v1.x.x/docs/tutorials/getting_started.md This is the complete code for a basic Frequenz SDK Python application, combining imports, microgrid initialization, and data reading logic. ```python import asyncio from datetime import timedelta from frequenz.sdk import microgrid from frequenz.sdk.timeseries import ResamplerConfig2 async def run() -> None: # This points to the default Frequenz microgrid sandbox server_url = "grpc://microgrid.sandbox.api.frequenz.io:62060" # Initialize the microgrid await microgrid.initialize( server_url, ResamplerConfig2(resampling_period=timedelta(seconds=1)), ) # Define your application logic here grid_meter = microgrid.grid().power.new_receiver() async for power in grid_meter: print(power.value) def main() -> None: asyncio.run(run()) if __name__ == "__main__": main() ``` -------------------------------- ### Install Pytest Dependencies and Run Pytest Source: https://github.com/frequenz-floss/frequenz-sdk-python/blob/v1.x.x/CONTRIBUTING.md Install dependencies for running Pytest and then execute Pytest manually to run tests. ```sh python -m pip install .[dev-pytest] pytest tests/test_*.py ``` -------------------------------- ### Implement Application Logic: Read Power Measurements Source: https://github.com/frequenz-floss/frequenz-sdk-python/blob/v1.x.x/docs/tutorials/getting_started.md Implement the core application logic within the `run` function. This example demonstrates reading power measurements from the microgrid's grid meter and printing the values. ```python async def run() -> None: # This points to the default Frequenz microgrid sandbox ... # Define your application logic here grid_meter = microgrid.grid().power.new_receiver() async for power in grid_meter: print(power.value) ``` -------------------------------- ### Verify SDK Installation Source: https://github.com/frequenz-floss/frequenz-sdk-python/blob/v1.x.x/docs/index.md Confirm that the Frequenz SDK has been installed correctly by importing it in the Python interpreter. This ensures the SDK is accessible for use in your project. ```python import frequenz.sdk ``` -------------------------------- ### Example Timeseries Data Source: https://github.com/frequenz-floss/frequenz-sdk-python/wiki/Glossary Illustrates a sequence of samples, each containing a timestamp and a measurement value. This example shows regular, second-interval measurements for a battery's capacity. ```text (2022-01-01 22:00:00.000 UTC, 400) (2022-01-01 22:00:01.000 UTC, 401) (2022-01-01 22:00:02.000 UTC, 403) (2022-01-01 22:00:03.000 UTC, 402) (2022-01-01 22:00:04.000 UTC, 403) ``` -------------------------------- ### Create and Activate Virtual Environment Source: https://github.com/frequenz-floss/frequenz-sdk-python/blob/v1.x.x/docs/index.md Set up a dedicated virtual environment for your project to manage dependencies. This isolates project packages from your global Python installation. ```sh mkdir my-sdk-project cd my-sdk-project python3 -m venv .venv . .venv/bin/activate ``` -------------------------------- ### Check Python Version Source: https://github.com/frequenz-floss/frequenz-sdk-python/blob/v1.x.x/docs/index.md Verify that your Python installation is version 3.11 or newer. This is a prerequisite for using the Frequenz Python SDK. ```console python3 --version ``` -------------------------------- ### Actor Constructor with Input Channel Receiver Source: https://github.com/frequenz-floss/frequenz-sdk-python/wiki/Actors-Style-Guide Actors receiving instructions via channels should have their channel receivers named according to the pattern '__receiver'. This example shows a receiver for a PowerDistributingActor's ResultMessage. ```python @actor class InputConsumingActor: def __init__(self, power_distributing_result_receiver: Receiver[PowerDistributingActor.ResultMessage]): self._power_distributing_result_receiver = power_distributing_result_receiver ``` -------------------------------- ### Run Application Source: https://github.com/frequenz-floss/frequenz-sdk-python/blob/v1.x.x/docs/tutorials/getting_started.md Execute your Frequenz SDK Python application from the command line. Ensure you have updated the microgrid host and port if not using the default sandbox. ```bash # Example usage python pv_optimization.py ``` -------------------------------- ### Build Project Documentation Source: https://github.com/frequenz-floss/frequenz-sdk-python/blob/v1.x.x/CONTRIBUTING.md Build the project documentation, which will be written to the 'site/' directory. ```sh mkdocs build ``` -------------------------------- ### Push Multi-Version Documentation to Fork Source: https://github.com/frequenz-floss/frequenz-sdk-python/blob/v1.x.x/CONTRIBUTING.md Deploy and push multi-version documentation to your fork's GitHub Pages. Replace 'your-fork-remote' with the name of your fork's remote. ```sh mike deploy --push --remote your-fork-remote ``` -------------------------------- ### Create Application Skeleton Source: https://github.com/frequenz-floss/frequenz-sdk-python/blob/v1.x.x/docs/tutorials/getting_started.md Define the main asynchronous function to initialize the microgrid connection. This sets up the server URL and configures the resampling period for time-series data. ```python async def run() -> None: # This points to the default Frequenz microgrid sandbox server_url = "grpc://microgrid.sandbox.api.frequenz.io:62060" # Initialize the microgrid await microgrid.initialize( server_url, ResamplerConfig2(resampling_period=timedelta(seconds=1)), ) # Define your application logic here # ... ``` -------------------------------- ### Build Source and Binary Distribution Source: https://github.com/frequenz-floss/frequenz-sdk-python/blob/v1.x.x/CONTRIBUTING.md Use this command to build the source and binary distribution of the project. ```sh python -m pip install build python -m build ``` -------------------------------- ### Serve Multi-Version Documentation with Mike Source: https://github.com/frequenz-floss/frequenz-sdk-python/blob/v1.x.x/CONTRIBUTING.md Serve the contents of the local 'gh-pages' branch using Mike. Note that changes to source files will not update live; a 'mike deploy' is required. ```sh mike serve ``` -------------------------------- ### Create and Activate Virtual Environment Source: https://github.com/frequenz-floss/frequenz-sdk-python/blob/v1.x.x/README.md Create a new virtual environment and activate it using sh-compatible shell commands. ```sh python3 -m venv .venv . .venv/bin/activate ``` -------------------------------- ### Reset Release Notes to Template Source: https://github.com/frequenz-floss/frequenz-sdk-python/blob/v1.x.x/CONTRIBUTING.md Copy the release notes template to the main release notes file after a release. ```sh cp .github/RELEASE_NOTES.template.md RELEASE_NOTES.md ``` -------------------------------- ### Deploy Multi-Version Documentation with Mike Source: https://github.com/frequenz-floss/frequenz-sdk-python/blob/v1.x.x/CONTRIBUTING.md Deploy a specific version of the documentation using Mike. This command builds the documentation and writes it to the local 'gh-pages' branch. ```sh mike deploy my-version ``` -------------------------------- ### Import Necessary Modules Source: https://github.com/frequenz-floss/frequenz-sdk-python/blob/v1.x.x/docs/tutorials/getting_started.md Import the required libraries for your Frequenz SDK application. This includes asyncio for asynchronous operations, timedelta for time durations, and specific modules from the frequenz.sdk. ```python import asyncio from datetime import timedelta from frequenz.sdk import microgrid from frequenz.sdk.timeseries import ResamplerConfig2 ``` -------------------------------- ### Run Mypy with Nox Source: https://github.com/frequenz-floss/frequenz-sdk-python/blob/v1.x.x/CONTRIBUTING.md Execute Mypy using Nox for static type checking, specifying the files to check. ```sh nox -R -s mypy -- test/test_*.py ``` -------------------------------- ### Set Default Version for Mike Serve Source: https://github.com/frequenz-floss/frequenz-sdk-python/blob/v1.x.x/CONTRIBUTING.md Set the default version for Mike to serve. This ensures that 'mike serve' displays the most recently deployed version. ```sh mike set-default my-version ``` -------------------------------- ### Run Pylint with Nox Source: https://github.com/frequenz-floss/frequenz-sdk-python/blob/v1.x.x/CONTRIBUTING.md Execute Pylint using Nox to check code quality, specifying the files to analyze. ```sh nox -R -s pylint -- test/test_*.py ``` -------------------------------- ### API Dependency Flowchart Source: https://github.com/frequenz-floss/frequenz-sdk-python/wiki/APIs-stack-and-repositories-structure Illustrates the dependency relationships between different API repositories, including common definitions and external protobuf dependencies. ```mermaid flowchart BT google[googleapis/api-common-protos] common[frequenz-api-common] api1[frequenz-api-xxx] api2[frequenz-api-yyy] apiN[frequenz-api-...] api1 --> google common --> google style s opacity:0 subgraph s[" "] api1 --> common api2 --> common apiN --> common end apiN -.->|sometimes| google ``` -------------------------------- ### Define Main Function Source: https://github.com/frequenz-floss/frequenz-sdk-python/blob/v1.x.x/docs/tutorials/getting_started.md Create a standard Python main function to run the asynchronous application logic using asyncio. This ensures the application can be executed directly. ```python def main() -> None: asyncio.run(run()) if __name__ == "__main__": main() ``` -------------------------------- ### Repository Dependency Graph Source: https://github.com/frequenz-floss/frequenz-sdk-python/wiki/APIs-stack-and-repositories-structure Visual representation of the dependencies between different Frequenz SDK repositories, illustrating the proposed API-centric structure. ```mermaid flowchart BT grpcclient[frequenz-grpcclient-python] common-spec[frequenz-common-proto-spec] common-bind[frequenz-common-bindings-python] common-wrap[frequenz-common-python] xxx-spec[frequenz-xxx-grpc-spec] xxx-service[frequenz-xxx-service] xxx-bind[frequenz-xxx-bindings-python] xxx-client[frequenz-xxx-client-python] xxx[frequenz-xxx-python] xxx --> xxx-client xxx-client -.->|sometimes| common-wrap xxx-client --> xxx-bind xxx-client --> grpcclient xxx-bind --> xxx-spec xxx-service --> xxx-spec xxx-spec -.->|sometimes| common-spec common-wrap --> common-bind common-bind --> common-spec ``` -------------------------------- ### Create Signed Git Tag for Release Source: https://github.com/frequenz-floss/frequenz-sdk-python/blob/v1.x.x/CONTRIBUTING.md Create a new signed Git tag for a release. The tag uses the release notes from RELEASE_NOTES.md and follows semantic versioning with a 'v' prefix. ```sh git tag -s --cleanup=whitespace -F RELEASE_NOTES.md v0.0.1 ``` -------------------------------- ### Handling Non-Conformant Class Names Source: https://github.com/frequenz-floss/frequenz-sdk-python/wiki/Actors-Style-Guide Use a comment to explain deviations from the standard naming convention when a class name does not follow the expected pattern. This ensures clarity for other developers. ```python # This class doesn't follow the naming convention because of class IHaveAWeirdName: ... ``` -------------------------------- ### Cross-Arch Dockerfile Naming Convention Source: https://github.com/frequenz-floss/frequenz-sdk-python/blob/v1.x.x/CONTRIBUTING.md Follows a naming scheme for Dockerfiles to facilitate use in CI build matrices for cross-architecture testing. ```bash --python-.Dockerfile ``` ```bash arm64-ubuntu-20.04-python-3.11.Dockerfile ``` -------------------------------- ### Run Pytest with Nox Source: https://github.com/frequenz-floss/frequenz-sdk-python/blob/v1.x.x/CONTRIBUTING.md Execute Pytest using Nox, specifying the test files to run. ```sh nox -R -s pytest -- test/test_*.py ``` -------------------------------- ### Reuse Current Testing Environment with Nox Source: https://github.com/frequenz-floss/frequenz-sdk-python/blob/v1.x.x/CONTRIBUTING.md Use Nox with the -R flag to reuse the current testing environment, which can speed up tests but may lead to a dirty environment. ```sh python -m pip install .[dev-noxfile] nox -R ``` -------------------------------- ### Actor Constructor with Output Sender Source: https://github.com/frequenz-floss/frequenz-sdk-python/wiki/Actors-Style-Guide Actors that produce output should receive the channel sender for that output in their constructor. The sender should be named 'output_sender'. ```python @actor class OutputProducingActor: def __init__(self, output_sender: Sender[OutputType]): self._output_sender = output_sender ``` -------------------------------- ### Defining Meaningful Message Types with NewType Source: https://github.com/frequenz-floss/frequenz-sdk-python/wiki/Actors-Style-Guide When an actor's message is a built-in type like an integer, define a NewType to give it a meaningful name and enable proper type checking. This helps differentiate messages from simple values. ```python from typing import NewType class PeakShavingActor: AppliedPowerMessage = NewType('AppliedPowerMessage', int) ... ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.