-
Notifications
You must be signed in to change notification settings - Fork 13
Edit README #219
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Edit README #219
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,7 +11,6 @@ A Python client for interacting with the Frequenz Reporting API to efficiently r | |
| > **Who should use this?** | ||
| > This client is for developers building applications on top of Frequenz's platform who need structured access to historical component or sensor data via Python or CLI. | ||
|
|
||
|
|
||
| ## Supported Platforms | ||
|
|
||
| The following platforms are officially supported (tested): | ||
|
|
@@ -25,42 +24,155 @@ The following platforms are officially supported (tested): | |
| If you want to know how to build this project and contribute to it, please | ||
| check out the [Contributing Guide](CONTRIBUTING.md). | ||
|
|
||
| ## Getting Started | ||
|
|
||
| ## Usage | ||
| To get started, create a directory for your project and follow the steps below to set up your development environment and run the client. | ||
|
|
||
| Please also refer to source of the [CLI tool](https://github.com/frequenz-floss/frequenz-client-reporting-python/blob/v0.x.x/src/frequenz/client/reporting/cli/__main__.py) | ||
| for a practical example of how to use the client. | ||
| ### 1. Install VS Code | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think we shouldn't advertise specific editors in this library. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed. |
||
|
|
||
| Download and install **Visual Studio Code** from the [official website](https://code.visualstudio.com/). | ||
|
|
||
| Once installed, add the following extensions: | ||
|
|
||
| - [Python extension](https://marketplace.visualstudio.com/items?itemName=ms-python.python) | ||
| - [Jupyter extension](https://marketplace.visualstudio.com/items?itemName=ms-toolsai.jupyter) | ||
|
|
||
| These enable Python development and interactive notebooks within VS Code. | ||
|
|
||
| ### 2. Set Up a Virtual Environment | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same for this section, not only relevant for reporting API. Do we have instructions on environments already somewhere documented @llucax ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The problem with documenting it here is that we will have to maintain similar sections in all client repositories. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Now we have https://github.com/frequenz-floss/docs/, so we can put common docs here and leave only project-specific stuff for the project. I think we still need some time to sort this out properly, but I have a rough idea of how we should move forward. |
||
|
|
||
| It is recommended to use a **virtual environment** for isolating dependencies. | ||
| When using a virtual environment, you create something like a sandbox or containerized workspace that isolates dependencies and packages so they don’t conflict with the system or other projects. After creating the virtual environment, you can install all packages you need for the current project. To set up an initial virtual environment for using the Reporting API, go through the following steps: | ||
|
|
||
| #### Linux / macOS | ||
|
|
||
| ```bash | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In general I like the idea of having copy paste friendly instructions. Maybe we should only focus on the reporting part in this case and skip the notebook part. I also suggest to create a separate manual page for dealing with notebooks and keep the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agreee with @matthias-wende-frequenz There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also this applies to most if not all projects, so probably something to be discussed here: |
||
| ### Go to your projects directory, open a terminal and run the following commands | ||
|
|
||
| # Create a virtual environment | ||
| python3 -m venv .venv | ||
|
|
||
| # Activate the environment | ||
| source .venv/bin/activate # when using bash | ||
| source .venv/bin/activate.fish # when using fish | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should stick with one example environment and let users with more niche configuration figure things out for themselves (i.e. skip fish and mention at the start of the readme that we assume Again something for: |
||
|
|
||
| # Install the version of the reporting client you want to use | ||
| pip install frequenz-client-reporting==0.18.0 | ||
|
|
||
| # Install python-dotenv | ||
| # --> Used to load environment variables from a `.env` file into the projects environment | ||
| pip install python-dotenv | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be optional There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And I would remove it, we shouldn't be so opinionated on how users should run stuff. We could provide some separate guide for a newbie with some opinionated suggested configuration and IDE, but that should be definitely not part of the README. |
||
|
|
||
| # Install ipkernel | ||
| # --> Python execution backend for Jupyter | ||
| pip install ipkernel | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also optional. Moreover I think there is a typo in the package name. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't even know what this is 😆 |
||
|
|
||
| # Register the virtual environment as a kernel | ||
| python -m ipykernel install --user --name=myenv --display-name "Python (myenv)" | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All of these things are optional and not required for the reporting API. |
||
|
|
||
| # Install pandas | ||
| pip install pandas | ||
|
|
||
| # Deactivate the environment | ||
| deactivate | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why deactivating the env? If users do this then nothing works. |
||
| ``` | ||
|
|
||
| #### Windows (PowerShell) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We are not officially supporting Windows yet, so I wouldn't include a section on how to install in a platform we don't officially support. Maybe we should start supporting Windows, but that's a separate discussion. Again, all of this is pretty general, so we probably should include it in docs for all projects. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In the context of making this a separate tutorial for newbies, we could even leave this section with a big warning saying that Windows is not YET officially supported. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well it might discourage some people start trying to use it on Windows and hence they might solve some issues for us on the way. |
||
|
|
||
| ```powershell | ||
| ### Go to your projects directory, open PowerShell and run the following commands | ||
|
|
||
| # Create a virtual environment | ||
| python -m venv .venv | ||
|
|
||
| ### Installation | ||
| # Activate the environment | ||
| .venv\Scripts\Activate.ps1 | ||
|
|
||
| # Install the version of the reporting client you want to use | ||
| pip install frequenz-client-reporting==0.18.0 | ||
|
|
||
| # Install python-dotenv | ||
| # --> Used to load environment variables from a `.env` file into the project's environment | ||
| pip install python-dotenv | ||
|
|
||
| # Install ipykernel | ||
| # --> Python execution backend for Jupyter | ||
| pip install ipykernel | ||
|
|
||
| # Register the virtual environment as a kernel | ||
| python -m ipykernel install --user --name=myenv --display-name "Python (myenv)" | ||
|
|
||
| # Install pandas | ||
| pip install pandas | ||
|
|
||
| # Deactivate the environment | ||
| deactivate | ||
| ``` | ||
|
|
||
| ## API Keys | ||
|
|
||
| To access the API, a key has to be created via Kuiper and stored locally on your computer. For that go through the following steps: | ||
|
|
||
| ### 1. create .env file | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is also opinionated, creating an |
||
|
|
||
| When creating the API key, you will get two keys. One is the API key itself and the other one is the API secret. Go to your projects directory and create a textfile named `.env` where you can store the API key and the API secret. | ||
| Prepare the textfile as follows: | ||
|
|
||
| ```bash | ||
| # Choose the version you want to install | ||
| VERSION=0.18.0 | ||
| pip install frequenz-client-reporting==$VERSION | ||
| # .env | ||
| REPORTING_API_AUTH_KEY= | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably good to follow our standard naming There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, please. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @cwasicki this is copied from the current README There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since we introduced signing keys we are trying to use these names as standard:
as using plain |
||
| REPORTING_API_SIGN_SECRET= | ||
| ``` | ||
|
|
||
| ### 2. Create API key via Kuiper | ||
|
|
||
| Log into your Kuiper account and click on your email-address on the bottom left. Then continue with `API keys` and `Create API key`. The created API key will be shown in the UI. This is the only time, the API key will be shown to you. whenever you loose it, you have to create a new one. | ||
| Copy the API key and the API secret and add it to the `.env` file. | ||
|
|
||
| ```bash | ||
| # .env | ||
| REPORTING_API_AUTH_KEY=EtQurK8LXA8vmEd4M6DqxeNp | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I hope this is not what it looks like. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can be relieved it's not an active key! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please remove the key no matter if valid or not and replace with just a template parameter like . Surely, you can find a suggestion from the GPTs of this world ;-) |
||
| REPORTING_API_SIGN_SECRET=DCG5x7XrJa2hN3spRTjVyQk9w16xXqR6hEUkYcoCG9yjx7Pp | ||
| ``` | ||
|
|
||
| ## Usage | ||
|
|
||
| Please also refer to source of the [CLI tool](https://github.com/frequenz-floss/frequenz-client-reporting-python/blob/v0.x.x/src/frequenz/client/reporting/cli/__main__.py) | ||
| for a practical example of how to use the client. | ||
|
|
||
| ### Create a notebook | ||
|
|
||
| Open your projects directory with VS Code. You should see your `.venv` and `.env` files in the directory when using VS Code. | ||
| Create a new `.ipynb` file (Jupyter notebook file) in the directory. When selecting the empty ipynb file, you will find `Select Kernel` on the top right of the file. Click on it and select `Jupyter Kernel > Python (myenv)`. Now the notebook will use your virtual environment as an interpreter. | ||
|
|
||
| ### Initialize the client | ||
|
|
||
| To use the Reporting API client, you need to initialize it with the server URL and authentication credentials. | ||
| The server URL should point to your Frequenz Reporting API instance, and you will need an authentication key and a signing secret. | ||
| See [this documentation](https://github.com/frequenz-floss/frequenz-client-base-python/blob/v0.x.x/README.md#authorization-and-signing) for further details. | ||
| The server URL should point to your Frequenz Reporting API instance, and you will need an authentication key and a signing secret, as described above. | ||
|
|
||
| > **Security Note** | ||
| > **SERVER URL:** | ||
| > Please ask your service administrator for the SERVER URL | ||
|
|
||
| > **Security Note:** | ||
| > Always keep your authentication key and signing secret secure. Do not hard-code them in your source code or share them publicly. | ||
|
|
||
| ```python | ||
| # Import basic packages | ||
| from dotenv import load_dotenv | ||
| from datetime import datetime, timedelta | ||
| import os | ||
| import pandas as pd | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why this import? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. to use pandas data frames |
||
|
|
||
| # Import Metrics and ReportingApiClient | ||
| from frequenz.client.common.metric import Metric | ||
| from frequenz.client.reporting import ReportingApiClient | ||
|
|
||
| # Change server address | ||
| # Read the API key from .env and sets it as environment variables in the current python process | ||
| load_dotenv() | ||
|
|
||
| # Create Reporting API Client | ||
| SERVER_URL = "grpc://replace-this-with-your-server-url:port" | ||
| AUTH_KEY = os.environ['REPORTING_API_AUTH_KEY'].strip() | ||
| # It is recommended to use a proper secret store to get the secret | ||
| # For local development, make sure not to leave it in the shell history | ||
| SIGN_SECRET= os.environ['REPORTING_API_SIGN_SECRET'].strip() | ||
| client = ReportingApiClient(server_url=SERVER_URL, auth_key=AUTH_KEY, sign_secret=SIGN_SECRET) | ||
| ``` | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not related to the reporting API, but a general recommendation how to set up a working environment. If we want to document this, I suggest to put it into another place than the reporting client README and link to it from here.
Apart from that, this sounds like vscode is required for the reporting API. It is not, and IMO it's overkill to recommend it.