|
| 1 | +[](https://sonarcloud.io/summary/new_code?id=softwareone-platform_mpt-tool) |
| 2 | +[](https://sonarcloud.io/summary/new_code?id=softwareone-platform_mpt-tool) |
| 3 | + |
| 4 | +[](https://github.com/astral-sh/ruff) |
| 5 | + |
1 | 6 | # mpt-api-python-client |
2 | 7 |
|
3 | 8 | A Python client for interacting with the MPT API. |
4 | 9 |
|
5 | | -## Installation |
| 10 | +## Documentation |
| 11 | + |
| 12 | +📚 **[Complete Usage Guide](docs/PROJECT_DESCRIPTION.md)** |
| 13 | + |
| 14 | +## Getting started |
| 15 | + |
| 16 | +### Prerequisites |
| 17 | + |
| 18 | +- Docker and Docker Compose plugin (`docker compose` CLI) |
| 19 | +- `make` |
| 20 | +- [CodeRabbit CLI](https://www.coderabbit.ai/cli) (optional. Used for running review check locally) |
| 21 | + |
| 22 | +### Make targets overview |
| 23 | + |
| 24 | +Common development workflows are wrapped in the `Makefile`. Run `make help` to see the list of available commands. |
6 | 25 |
|
7 | | -Install as a uv dependency: |
| 26 | +### How the Makefile works |
| 27 | + |
| 28 | +The project uses a modular Makefile structure that organizes commands into logical groups: |
| 29 | +- **Main Makefile** (`Makefile`): Entry point that automatically includes all `.mk` files from the `make/` directory |
| 30 | +- **Modular includes** (`make/*.mk`): Commands are organized by category: |
| 31 | + - `common.mk` - Core development commands (build, test, format, etc.) |
| 32 | + - `repo.mk` - Repository management and dependency commands |
| 33 | + - `migrations.mk` - Database migration commands (Only available in extension repositories) |
| 34 | + - `external_tools.mk` - Integration with external tools |
| 35 | + |
| 36 | + |
| 37 | +You can extend the Makefile with your own custom commands creating a `local.mk` file inside make folder. This file is |
| 38 | +automatically ignored by git, so your personal commands won't affect other developers or appear in version control. |
| 39 | + |
| 40 | + |
| 41 | +### Setup |
| 42 | + |
| 43 | +Follow these steps to set up the development environment: |
| 44 | + |
| 45 | +#### 1. Clone the repository |
8 | 46 |
|
9 | 47 | ```bash |
10 | | -uv add mpt-api-client |
11 | | -cp .env.example .env |
| 48 | +git clone <repository-url> |
| 49 | +``` |
| 50 | +```bash |
| 51 | +cd mpt-api-python-client |
12 | 52 | ``` |
13 | 53 |
|
14 | | -## Usage |
15 | | - |
16 | | -```python |
17 | | -from mpt_api_client import MPTClient |
| 54 | +#### 2. Create environment configuration |
18 | 55 |
|
19 | | -#client = MPTClient(api_key=os.getenv("MPT_API_KEY"), base_url=os.getenv("MPT_API_URL")) |
20 | | -client = MPTClient() # Will get the api_key and base_url from the environment variables |
| 56 | +Copy the sample environment file and update it with your values: |
21 | 57 |
|
22 | | -for product in client.catalog.products.iterate(): |
23 | | - print(product.name) |
| 58 | +```bash |
| 59 | +cp .env.sample .env |
24 | 60 | ``` |
25 | 61 |
|
26 | | -## Async Usage |
| 62 | +Edit the `.env` file with your actual configuration values. See the [Configuration](#configuration) section for details on available variables. |
27 | 63 |
|
28 | | -```python |
29 | | -import asyncio |
30 | | -from mpt_api_client import AsyncMPTClient |
| 64 | +#### 3. Build the Docker images |
31 | 65 |
|
32 | | -async def main(): |
33 | | - # client = AsyncMPTClient(api_key=os.getenv("MPT_API_KEY"), base_url=os.getenv("MPT_API_URL")) |
34 | | - client = AsyncMPTClient() # Will get the api_key and base_url from the environment variables |
35 | | - async for product in client.catalog.products.iterate(): |
36 | | - print(product.name) |
| 66 | +Build the development environment: |
37 | 67 |
|
38 | | -asyncio.run(main()) |
| 68 | +```bash |
| 69 | +make build |
39 | 70 | ``` |
40 | 71 |
|
41 | | -## Development |
| 72 | +This will create the Docker images with all required dependencies and the virtualenv. |
| 73 | + |
| 74 | +#### 4. Verify the setup |
42 | 75 |
|
43 | | -Clone the repository and install dependencies: |
| 76 | +Run the test suite to ensure everything is configured correctly: |
44 | 77 |
|
45 | 78 | ```bash |
46 | | -git clone https://github.com/albertsola/mpt-api-python-client.git |
47 | | -cd mpt-api-python-client |
48 | | -uv add -r requirements.txt |
| 79 | +make test |
49 | 80 | ``` |
50 | 81 |
|
51 | | -## Testing |
| 82 | +You're now ready to start developing! See [Running the client](#running-the-client) for next steps. |
| 83 | + |
52 | 84 |
|
53 | | -Run all validations with: |
| 85 | +## Running the client |
| 86 | + |
| 87 | +Before running, ensure your `.env` file is populated. |
54 | 88 |
|
55 | 89 | ```bash |
56 | | -make test-all |
| 90 | +make run |
57 | 91 | ``` |
58 | 92 |
|
59 | | -Run pytest with: |
| 93 | +## Developer utilities |
| 94 | + |
| 95 | +Useful helper targets during development: |
60 | 96 |
|
61 | 97 | ```bash |
62 | | -make test-all |
| 98 | +make bash # open a bash shell in the app container |
| 99 | +make check # run ruff, flake8, and lockfile checks |
| 100 | +make check-all # run checks and tests |
| 101 | +make format # auto-format code and imports |
| 102 | +make review # check the code in the cli by running CodeRabbit |
63 | 103 | ``` |
64 | | -## License |
65 | 104 |
|
66 | | -MIT |
| 105 | +## Configuration |
| 106 | + |
| 107 | +The following environment variables are typically set in `.env`. Docker Compose reads them when using the Make targets described above. |
| 108 | + |
| 109 | +### Application |
| 110 | + |
| 111 | +| Environment Variable | Default | Example | Description | |
| 112 | +|---------------------------------|---------|-------------------------------------------|-------------------------------------------------------------------------------------------| |
| 113 | +| `MPT_API_BASE_URL` | - | `https://portal.softwareone.com/mpt` | SoftwareONE Marketplace API URL | |
| 114 | +| `MPT_API_TOKEN` | - | eyJhbGciOiJSUzI1N... | SoftwareONE Marketplace API Token | |
| 115 | + |
| 116 | +### E2E |
| 117 | + |
| 118 | +| Environment Variable | Default | Example | Description | |
| 119 | +|----------------------------|---------|--------------------------------------|----------------------------------------------| |
| 120 | +| `MPT_API_TOKEN_CLIENT` | - | eyJhbGciOiJSUzI1N... | SoftwareONE Marketplace API Client Token | |
| 121 | +| `MPT_API_TOKEN_OPERATIONS` | - | eyJhbGciOiJSUzI1N... | SoftwareONE Marketplace API Operations Token | |
| 122 | +| `MPT_API_TOKEN_VENDOR` | - | eyJhbGciOiJSUzI1N... | SoftwareONE Marketplace API Vendor Token | |
| 123 | +| `RP_API_KEY` | - | pytest_XXXXXXXXXXXXXX | ReportPortal API key | |
| 124 | +| `RP_ENDPOINT` | - | `https://reportportal.example.com` | ReportPortal endpoint | |
| 125 | +| `RP_LAUNCH` | - | `dev-env` | ReportPortal launch | |
0 commit comments