Metadata-Version: 2.4
Name: pytr
Version: 0.4.10
Summary: Use TradeRepublic in terminal
Project-URL: Homepage, https://github.com/pytr-org/pytr
Author-email: marzzzello <853485-marzzzello@users.noreply.gitlab.com>
License: MIT
License-File: LICENSE
Classifier: Development Status :: 3 - Alpha
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Topic :: Office/Business :: Financial
Classifier: Topic :: Office/Business :: Financial :: Investment
Requires-Python: >=3.10
Requires-Dist: babel
Requires-Dist: certifi
Requires-Dist: coloredlogs
Requires-Dist: cryptography
Requires-Dist: curl-cffi
Requires-Dist: packaging
Requires-Dist: pathvalidate
Requires-Dist: pygments
Requires-Dist: requests-futures
Requires-Dist: shtab
Requires-Dist: websockets>=14
Provides-Extra: playwright
Requires-Dist: playwright>=1.62.0; extra == 'playwright'
Description-Content-Type: text/markdown

[![GitHub tag (with filter)](https://img.shields.io/github/v/tag/pytr-org/pytr?style=for-the-badge&link=https%3A%2F%2Fgithub.com%2Fmarzzzello%2Fpytr%2Ftags)](https://github.com/pytr-org/pytr/tags)
[![PyPI build and publish](https://img.shields.io/github/actions/workflow/status/pytr-org/pytr/publish-pypi.yml?link=https%3A%2F%2Fgithub.com%2Fmarzzzello%2Fpytr%2Factions%2Fworkflows%2Fpublish-pypi.yml&style=for-the-badge)](https://github.com/pytr-org/pytr/actions/workflows/publish-pypi.yml)
[![PyPI - Version](https://img.shields.io/pypi/v/pytr?link=https%3A%2F%2Fpypi.org%2Fproject%2Fpytr%2F&style=for-the-badge)](https://pypi.org/project/pytr/)

# pytr: Use TradeRepublic in terminal

This is a library for the private API of the Trade Republic online brokerage. It is not affiliated with Trade Republic
Bank GmbH.

__Table of Contents__

<!-- toc -->
* [Quickstart](#quickstart)
* [Usage](#usage)
* [Authentication](#authentication)
  * [Web login](#web-login)
* [Development](#development)
  * [Setting Up a Development Environment](#setting-up-a-development-environment)
  * [Linting and Code Formatting](#linting-and-code-formatting)
  * [Release process](#release-process)
  * [Keep the readme updated](#keep-the-readme-updated)
* [License](#license)
<!-- end toc -->

## Quickstart

This is the right section for you if all you want to do is to "just run the thing". Whether you've never run a piece
of code before, or are new to Python, these steps will make it the easiest for you to run pytr.

We strongly recommend that you use [`uv`](https://docs.astral.sh/uv/#installation) to run pytr. Since pytr is written
in the Python programming language, you usually need to make sure you have an installation of Python on your computer
before you can run any Python program. However, uv will take care of installing an appropriate Python version for
you if you don't already have one.

To install uv on OSX/Linux, run:

```sh
 curl -LsSf https://astral.sh/uv/install.sh | sh
```

On Windows, run:

```sh
 powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"
```

Then, to run the latest released version of pytr:

```sh
 uvx pytr@latest
```

If you want to use the cutting-edge version, use this command instead:

```sh
 uvx --with git+https://github.com/pytr-org/pytr.git pytr
```

## Usage

<!-- runcmd code:console uv run --python 3.13 pytr help --for-readme -->
```console
usage: pytr [-h] [-V] [-v {warning,info,debug}] [--debug-logfile DEBUG_LOGFILE] [--debug-log-filter DEBUG_LOG_FILTER]
            {help,login,portfolio,rates,details,dl_docs,export_transactions,get_price_alarms,set_price_alarms,get_savings_plans,completion} ...

Use "pytr command_name --help" to get detailed help to a specific command

Commands:
  {help,login,portfolio,rates,details,dl_docs,export_transactions,get_price_alarms,set_price_alarms,get_savings_plans,completion}
                                        Desired action to perform
    help                                Print this help message
    login                               Check if credentials file exists. If not create it and ask for input. Try to
                                        login. Ask for device reset if needed
    portfolio                           Show current portfolio
    rates                               Fetch current prices for a list of ISINs given as direct list or CSV input
    details                             Get details for an ISIN
    dl_docs                             Download all pdf documents from the timeline and sort them into folders. Also
                                        export account transactions (account_transactions.csv) and JSON files with all
                                        events (events_with_documents.json and other_events.json)
    export_transactions                 Read data from the TR timeline and export transactions into a file, e.g. as csv
                                        into account_transactions.csv.
    get_price_alarms                    Get current price alarms
    set_price_alarms                    Set new price alarms
    get_savings_plans                   Get current savings plans
    completion                          Print shell tab completion

Options:
  -h, --help                            show this help message and exit
  -V, --version                         Print version information and quit (default: False)
  -v, --verbosity {warning,info,debug}  Set verbosity level (default: info) (default: info)
  --debug-logfile DEBUG_LOGFILE         Dump debug logs to a file (default: None)
  --debug-log-filter DEBUG_LOG_FILTER   Filter debug log types (default: None)
```
<!-- end runcmd -->

## Authentication

### Web login

Web login uses the public web-login endpoints at `api.traderepublic.com`. Two variants are available:

- **v1 (default)**: `pytr login`. You receive a four-digit code in the TradeRepublic app (or via SMS as a
  fallback) and enter it in the terminal. This is the original behavior; nothing changes for existing users.
  v1 requires passing an AWS WAF token with the login request; by default pytr fetches one automatically
  via Playwright (requires the optional `playwright` extra: `pip install 'pytr[playwright]' && playwright install chromium`).
  The pure-Python alternative `--waf-token awswaf` exists but has been reported to no longer work reliably.
- **v2 (opt-in)**: `pytr login --v2`. Mirrors what
  [app.traderepublic.com](https://app.traderepublic.com/) currently does. Instead of typing a four-digit code, you
  confirm the login from a push notification in the Trade Republic mobile app. Accounts secured with an authenticator
  app are asked for a code from that app instead. Useful if your account no longer issues a code via the app or SMS.
  v2 does not require a WAF token; pytr skips it automatically when `--v2` is used.
  Note that Trade Republic removed the SMS resend endpoint along with the v1 web login, so there is no SMS fallback
  under `--v2`. The flag is available on every subcommand that performs a login, e.g. `pytr portfolio --v2`,
  `pytr dl_docs --v2`.

Both variants keep you logged in on your primary device, but you may need to re-authenticate every so often when
running `pytr`.

## Development

### Setting Up a Development Environment

Clone the repository:

```sh
 git clone https://github.com/pytr-org/pytr.git
```

Install dependencies:

```sh
 uv sync
```

Run the tests to ensure everything is set up correctly:

```sh
 uv run pytest
```

### Linting and Code Formatting

This project uses [Ruff](https://astral.sh/ruff) for code linting and auto-formatting, as well as
[Mypy](https://www.mypy-lang.org/) for type checking.

You can auto-format the code with Ruff by running:

```bash
uv run ruff format            # Format code
uv run ruff check --fix-only  # Remove unneeded imports, order imports, etc.
```

You can check the typing of the code with Mypy by running:

```bash
uv run mypy .
```

Ruff and Mypy run as part of CI and your Pull Request cannot be merged unless it satisfies the linting, formatting
checks and type checks.

### Release process

1. Create a pull request that bumps the version number in `pyproject.toml`
2. After successfully merging the PR, [create a new release](https://github.com/pytr-org/pytr/releases/new) via GitHub
   and make use of the "Generate release notes" button. Tags are formatted as `vX.Y.Z`.
3. The package will be published to PyPI from CI.

### Keep the readme updated

This readme contains a few automatically generated bits. To keep them up to date, simply run the following command: (Never start it from an activated venv!)

```sh
 uvx mksync@0.1.5 -i README.md
```

## License

This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.
