igaming-market-sdk 1.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,40 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ pull_request:
7
+ branches: [main]
8
+
9
+ permissions:
10
+ contents: read
11
+
12
+ jobs:
13
+ test-and-security:
14
+ runs-on: ubuntu-latest
15
+ strategy:
16
+ matrix:
17
+ python-version: ["3.10", "3.11", "3.12"]
18
+
19
+ steps:
20
+ - name: Checkout repository
21
+ uses: actions/checkout@v4
22
+
23
+ - name: Set up Python ${{ matrix.python-version }}
24
+ uses: actions/setup-python@v5
25
+ with:
26
+ python-version: ${{ matrix.python-version }}
27
+
28
+ - name: Install package and dev tools
29
+ run: |
30
+ python -m pip install --upgrade pip
31
+ pip install -e ".[dev]"
32
+
33
+ - name: Lint with Ruff
34
+ run: ruff check src tests
35
+
36
+ - name: Static security analysis with Bandit
37
+ run: bandit -r src -ll
38
+
39
+ - name: Run unit tests with Pytest
40
+ run: pytest -v
@@ -0,0 +1,34 @@
1
+ name: Publish to PyPI
2
+
3
+ on:
4
+ release:
5
+ types: [published]
6
+
7
+ permissions:
8
+ contents: read
9
+
10
+ jobs:
11
+ build-and-publish:
12
+ runs-on: ubuntu-latest
13
+ environment:
14
+ name: pypi
15
+ url: https://pypi.org/p/igaming-market-sdk
16
+ permissions:
17
+ id-token: write
18
+
19
+ steps:
20
+ - name: Checkout repository
21
+ uses: actions/checkout@v4
22
+
23
+ - name: Set up Python
24
+ uses: actions/setup-python@v5
25
+ with:
26
+ python-version: "3.12"
27
+
28
+ - name: Build distribution packages
29
+ run: |
30
+ python -m pip install --upgrade pip build
31
+ python -m build
32
+
33
+ - name: Publish to PyPI via Trusted Publishing
34
+ uses: pypa/gh-action-pypi-publish@release/v1
@@ -0,0 +1,11 @@
1
+ __pycache__/
2
+ *.py[cod]
3
+ *$py.class
4
+ *.egg-info/
5
+ .pytest_cache/
6
+ .ruff_cache/
7
+ dist/
8
+ build/
9
+ .venv/
10
+ venv/
11
+ .env
@@ -0,0 +1,12 @@
1
+ # Changelog
2
+
3
+ All notable changes to `igaming-market-sdk` will be documented in this file.
4
+ The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/) and [Semantic Versioning](https://semver.org/).
5
+
6
+ ## [1.0.0] - 2026-11-29
7
+
8
+ ### Added
9
+ - Initial public release of `IGamingMarketClient` with full support for `/v1/markets`, `/v1/geo`, `/v1/providers`, `/v1/games/search`, and `/v1/calculate/wagering`.
10
+ - Built-in CLI entrypoint (`igaming-market`).
11
+ - Strict local input validation (`IGamingValidationError`) and structured HTTP error handling (`IGamingAPIError`).
12
+ - Offline unit test suite using `httpx.MockTransport` and GitHub Actions CI (`pytest`, `ruff`, `bandit`).
@@ -0,0 +1,20 @@
1
+ cff-version: 1.2.0
2
+ title: "igaming-market-sdk: Python SDK for the 2WinPower iGaming Market Compliance & Slot Metadata API"
3
+ message: "If you use this software or API client in research or analytics workflows, please cite it using these metadata."
4
+ type: software
5
+ authors:
6
+ - name: "2WinPower Engineering Team"
7
+ email: "info@2wpower.com"
8
+ website: "https://2wpower.com"
9
+ version: "1.0.0"
10
+ date-released: "2026-11-29"
11
+ license: MIT
12
+ url: "https://2wpower.com"
13
+ repository-code: "https://github.com/2winpower-dev/igaming-market-sdk"
14
+ keywords:
15
+ - igaming
16
+ - regtech
17
+ - compliance
18
+ - payments
19
+ - open-data
20
+ - python-sdk
@@ -0,0 +1,26 @@
1
+ # Contributing to igaming-market-sdk
2
+
3
+ Contributions, bug reports, and documentation improvements are welcome.
4
+
5
+ ## Reporting Bugs or Requesting Features
6
+
7
+ Please open an issue in [GitHub Issues](https://github.com/2winpower-dev/igaming-market-sdk/issues) with:
8
+ - Python version and OS
9
+ - Minimal reproduction snippet
10
+ - Expected vs. actual behavior
11
+
12
+ ## Pull Request Workflow
13
+
14
+ 1. Fork the repository and create a feature branch from `main`.
15
+ 2. Install development dependencies:
16
+ ```bash
17
+ pip install -e ".[dev]"
18
+ ```
19
+ 3. Add or update unit tests in `tests/` for any behavioral changes.
20
+ 4. Ensure linting, static security analysis, and tests pass locally:
21
+ ```bash
22
+ ruff check src tests
23
+ bandit -r src -ll
24
+ pytest -v
25
+ ```
26
+ 5. Open a Pull Request describing your changes clearly.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 2WinPower
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,141 @@
1
+ Metadata-Version: 2.5
2
+ Name: igaming-market-sdk
3
+ Version: 1.0.0
4
+ Summary: Python SDK and CLI for the 2WinPower iGaming Market Compliance, Payment Rails, Slot Metadata & Wagering API.
5
+ Project-URL: Homepage, https://2wpower.com
6
+ Project-URL: Documentation, https://api.2wpower.com/docs
7
+ Project-URL: Repository, https://github.com/2winpower-dev/igaming-market-sdk
8
+ Project-URL: Issues, https://github.com/2winpower-dev/igaming-market-sdk/issues
9
+ Project-URL: Changelog, https://github.com/2winpower-dev/igaming-market-sdk/blob/main/CHANGELOG.md
10
+ Author-email: 2WinPower Engineering Team <info@2wpower.com>
11
+ License: MIT License
12
+
13
+ Copyright (c) 2026 2WinPower
14
+
15
+ Permission is hereby granted, free of charge, to any person obtaining a copy
16
+ of this software and associated documentation files (the "Software"), to deal
17
+ in the Software without restriction, including without limitation the rights
18
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
19
+ copies of the Software, and to permit persons to whom the Software is
20
+ furnished to do so, subject to the following conditions:
21
+
22
+ The above copyright notice and this permission notice shall be included in all
23
+ copies or substantial portions of the Software.
24
+
25
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
26
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
27
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
28
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
29
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
30
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
31
+ SOFTWARE.
32
+ License-File: LICENSE
33
+ Keywords: 2winpower,compliance,igaming,open-data,payments,regtech,rest-api,sdk
34
+ Classifier: Development Status :: 5 - Production/Stable
35
+ Classifier: Intended Audience :: Developers
36
+ Classifier: License :: OSI Approved :: MIT License
37
+ Classifier: Operating System :: OS Independent
38
+ Classifier: Programming Language :: Python :: 3
39
+ Classifier: Programming Language :: Python :: 3.9
40
+ Classifier: Programming Language :: Python :: 3.10
41
+ Classifier: Programming Language :: Python :: 3.11
42
+ Classifier: Programming Language :: Python :: 3.12
43
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
44
+ Requires-Python: >=3.9
45
+ Requires-Dist: httpx<1.0.0,>=0.27.0
46
+ Provides-Extra: dev
47
+ Requires-Dist: bandit>=1.7.9; extra == 'dev'
48
+ Requires-Dist: pytest>=8.0.0; extra == 'dev'
49
+ Requires-Dist: ruff>=0.6.0; extra == 'dev'
50
+ Description-Content-Type: text/markdown
51
+
52
+ # igaming-market-sdk
53
+
54
+ Official lightweight Python SDK and CLI for the public **2WinPower iGaming Market Compliance, Payment Rails, Slot Metadata & Wagering API** (`https://api.2wpower.com`), maintained by [2WinPower](https://2wpower.com).
55
+
56
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
57
+
58
+ ## Features
59
+
60
+ - **Keyless Public API:** No API key required; communicates strictly over HTTPS.
61
+ - **Global Market & Compliance Profiles (`40+` countries):** Regulatory status, GGR tax benchmarks, legal age limits, and dominant local payment rails (PIX, UPI, Interac, OPay, Bizum, Blik, M-Pesa, etc.).
62
+ - **Game & Studio Directory:** Provider licenses, flagship slot metadata, default RTP, volatility tiers, and game mechanics.
63
+ - **Bonus Wagering & EV Calculator:** Mathematical computation of required turnover, house edge, theoretical GGR, and expected value.
64
+ - **Zero Heavy Dependencies:** Built solely on `httpx` with full offline unit-test coverage and a built-in CLI.
65
+
66
+ ## Installation
67
+
68
+ ```bash
69
+ pip install igaming-market-sdk
70
+ ```
71
+
72
+ Or install directly from GitHub:
73
+
74
+ ```bash
75
+ pip install "git+https://github.com/2winpower-dev/igaming-market-sdk.git"
76
+ ```
77
+
78
+ ## Quick Start (Python)
79
+
80
+ ```python
81
+ from igaming_market_sdk import IGamingMarketClient
82
+
83
+ with IGamingMarketClient() as client:
84
+ # 1. Fetch compliance & payment profile for Brazil
85
+ brazil = client.get_geo("BR")
86
+ print(brazil["regulation"]["tax_ggr_percent"], brazil["payments"]["top_methods"])
87
+
88
+ # 2. Search slot metadata
89
+ slots = client.search_games("sweet")
90
+ print(slots["total_results"], [item["title"] for item in slots["items"]])
91
+
92
+ # 3. Calculate wagering turnover and expected value
93
+ ev = client.calculate_wagering(
94
+ deposit_amount=100,
95
+ bonus_amount=100,
96
+ wagering_multiplier=35,
97
+ slot_rtp_percent=96.2,
98
+ )
99
+ print(ev)
100
+ ```
101
+
102
+ ## CLI Usage
103
+
104
+ ```bash
105
+ igaming-market geo BR
106
+ igaming-market markets
107
+ igaming-market providers
108
+ igaming-market search sweet
109
+ igaming-market wagering --deposit 100 --bonus 100 --multiplier 35 --rtp 96.2
110
+ ```
111
+
112
+ ## API Endpoints Covered
113
+
114
+ | SDK Method | HTTP Endpoint | Description |
115
+ | :--- | :--- | :--- |
116
+ | `list_markets()` | `GET /v1/markets` | List all supported market profiles |
117
+ | `get_geo(country_code)` | `GET /v1/geo?country=BR` | Compliance, tax, and payment rails for an ISO-2 country |
118
+ | `list_providers()` | `GET /v1/providers` | Game provider directory and licensing metadata |
119
+ | `search_games(query)` | `GET /v1/games/search?q=...` | Search games by title, provider, or category |
120
+ | `calculate_wagering(...)` | `POST /v1/calculate/wagering` | Bonus turnover, house edge, and EV calculator |
121
+
122
+ ## Related Resources
123
+
124
+ - **Official Website:** [2WinPower](https://2wpower.com)
125
+ - **Interactive Swagger Documentation:** [api.2wpower.com/docs](https://api.2wpower.com/docs)
126
+ - **OpenAPI 3.0 Specification:** [api.2wpower.com/openapi.json](https://api.2wpower.com/openapi.json)
127
+ - **Open Regulatory Dataset (Zenodo DOI):** [10.5281/zenodo.24585730](https://doi.org/10.5281/zenodo.24585730)
128
+
129
+ ## Development & Testing
130
+
131
+ ```bash
132
+ pip install -e ".[dev]"
133
+ ruff check src tests
134
+ bandit -r src -ll
135
+ pytest -v
136
+ ```
137
+
138
+ ## Security & License
139
+
140
+ - Security vulnerability reporting policy: see [SECURITY.md](SECURITY.md).
141
+ - Released under the [MIT License](LICENSE).
@@ -0,0 +1,90 @@
1
+ # igaming-market-sdk
2
+
3
+ Official lightweight Python SDK and CLI for the public **2WinPower iGaming Market Compliance, Payment Rails, Slot Metadata & Wagering API** (`https://api.2wpower.com`), maintained by [2WinPower](https://2wpower.com).
4
+
5
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
6
+
7
+ ## Features
8
+
9
+ - **Keyless Public API:** No API key required; communicates strictly over HTTPS.
10
+ - **Global Market & Compliance Profiles (`40+` countries):** Regulatory status, GGR tax benchmarks, legal age limits, and dominant local payment rails (PIX, UPI, Interac, OPay, Bizum, Blik, M-Pesa, etc.).
11
+ - **Game & Studio Directory:** Provider licenses, flagship slot metadata, default RTP, volatility tiers, and game mechanics.
12
+ - **Bonus Wagering & EV Calculator:** Mathematical computation of required turnover, house edge, theoretical GGR, and expected value.
13
+ - **Zero Heavy Dependencies:** Built solely on `httpx` with full offline unit-test coverage and a built-in CLI.
14
+
15
+ ## Installation
16
+
17
+ ```bash
18
+ pip install igaming-market-sdk
19
+ ```
20
+
21
+ Or install directly from GitHub:
22
+
23
+ ```bash
24
+ pip install "git+https://github.com/2winpower-dev/igaming-market-sdk.git"
25
+ ```
26
+
27
+ ## Quick Start (Python)
28
+
29
+ ```python
30
+ from igaming_market_sdk import IGamingMarketClient
31
+
32
+ with IGamingMarketClient() as client:
33
+ # 1. Fetch compliance & payment profile for Brazil
34
+ brazil = client.get_geo("BR")
35
+ print(brazil["regulation"]["tax_ggr_percent"], brazil["payments"]["top_methods"])
36
+
37
+ # 2. Search slot metadata
38
+ slots = client.search_games("sweet")
39
+ print(slots["total_results"], [item["title"] for item in slots["items"]])
40
+
41
+ # 3. Calculate wagering turnover and expected value
42
+ ev = client.calculate_wagering(
43
+ deposit_amount=100,
44
+ bonus_amount=100,
45
+ wagering_multiplier=35,
46
+ slot_rtp_percent=96.2,
47
+ )
48
+ print(ev)
49
+ ```
50
+
51
+ ## CLI Usage
52
+
53
+ ```bash
54
+ igaming-market geo BR
55
+ igaming-market markets
56
+ igaming-market providers
57
+ igaming-market search sweet
58
+ igaming-market wagering --deposit 100 --bonus 100 --multiplier 35 --rtp 96.2
59
+ ```
60
+
61
+ ## API Endpoints Covered
62
+
63
+ | SDK Method | HTTP Endpoint | Description |
64
+ | :--- | :--- | :--- |
65
+ | `list_markets()` | `GET /v1/markets` | List all supported market profiles |
66
+ | `get_geo(country_code)` | `GET /v1/geo?country=BR` | Compliance, tax, and payment rails for an ISO-2 country |
67
+ | `list_providers()` | `GET /v1/providers` | Game provider directory and licensing metadata |
68
+ | `search_games(query)` | `GET /v1/games/search?q=...` | Search games by title, provider, or category |
69
+ | `calculate_wagering(...)` | `POST /v1/calculate/wagering` | Bonus turnover, house edge, and EV calculator |
70
+
71
+ ## Related Resources
72
+
73
+ - **Official Website:** [2WinPower](https://2wpower.com)
74
+ - **Interactive Swagger Documentation:** [api.2wpower.com/docs](https://api.2wpower.com/docs)
75
+ - **OpenAPI 3.0 Specification:** [api.2wpower.com/openapi.json](https://api.2wpower.com/openapi.json)
76
+ - **Open Regulatory Dataset (Zenodo DOI):** [10.5281/zenodo.24585730](https://doi.org/10.5281/zenodo.24585730)
77
+
78
+ ## Development & Testing
79
+
80
+ ```bash
81
+ pip install -e ".[dev]"
82
+ ruff check src tests
83
+ bandit -r src -ll
84
+ pytest -v
85
+ ```
86
+
87
+ ## Security & License
88
+
89
+ - Security vulnerability reporting policy: see [SECURITY.md](SECURITY.md).
90
+ - Released under the [MIT License](LICENSE).
@@ -0,0 +1,24 @@
1
+ # Security Policy
2
+
3
+ ## Supported Versions
4
+
5
+ | Version | Supported |
6
+ | :--- | :--- |
7
+ | `1.x` | Yes |
8
+
9
+ ## Reporting a Vulnerability
10
+
11
+ We take the security of `igaming-market-sdk` and the underlying `api.2wpower.com` endpoints seriously.
12
+
13
+ If you discover a security vulnerability in this SDK or its API integration, please report it responsibly:
14
+
15
+ - **Email:** `info@2wpower.com` (Subject: `[Security] igaming-market-sdk vulnerability report`)
16
+ - **Alternative:** Open a private security advisory in the **Security** tab of this GitHub repository.
17
+
18
+ ### What to Expect
19
+
20
+ - **Acknowledgement:** Within 48 hours of receiving your report.
21
+ - **Assessment & Fix:** Confirmed vulnerabilities are prioritized and patched in the next minor/patch release with a published changelog entry.
22
+ - **Safe Harbor:** Good-faith security research conducted without disrupting production services will not result in legal action.
23
+
24
+ Please do not disclose security vulnerabilities publicly before a fix has been released.
@@ -0,0 +1,70 @@
1
+ [build-system]
2
+ requires = ["hatchling>=1.24.0"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "igaming-market-sdk"
7
+ version = "1.0.0"
8
+ description = "Python SDK and CLI for the 2WinPower iGaming Market Compliance, Payment Rails, Slot Metadata & Wagering API."
9
+ readme = "README.md"
10
+ license = { file = "LICENSE" }
11
+ requires-python = ">=3.9"
12
+ authors = [
13
+ { name = "2WinPower Engineering Team", email = "info@2wpower.com" }
14
+ ]
15
+ keywords = [
16
+ "igaming",
17
+ "regtech",
18
+ "compliance",
19
+ "payments",
20
+ "open-data",
21
+ "sdk",
22
+ "rest-api",
23
+ "2winpower"
24
+ ]
25
+ classifiers = [
26
+ "Development Status :: 5 - Production/Stable",
27
+ "Intended Audience :: Developers",
28
+ "License :: OSI Approved :: MIT License",
29
+ "Operating System :: OS Independent",
30
+ "Programming Language :: Python :: 3",
31
+ "Programming Language :: Python :: 3.9",
32
+ "Programming Language :: Python :: 3.10",
33
+ "Programming Language :: Python :: 3.11",
34
+ "Programming Language :: Python :: 3.12",
35
+ "Topic :: Software Development :: Libraries :: Python Modules",
36
+ ]
37
+ dependencies = [
38
+ "httpx>=0.27.0,<1.0.0",
39
+ ]
40
+
41
+ [project.optional-dependencies]
42
+ dev = [
43
+ "pytest>=8.0.0",
44
+ "ruff>=0.6.0",
45
+ "bandit>=1.7.9",
46
+ ]
47
+
48
+ [project.scripts]
49
+ igaming-market = "igaming_market_sdk.cli:main"
50
+
51
+ [project.urls]
52
+ Homepage = "https://2wpower.com"
53
+ Documentation = "https://api.2wpower.com/docs"
54
+ Repository = "https://github.com/2winpower-dev/igaming-market-sdk"
55
+ Issues = "https://github.com/2winpower-dev/igaming-market-sdk/issues"
56
+ Changelog = "https://github.com/2winpower-dev/igaming-market-sdk/blob/main/CHANGELOG.md"
57
+
58
+ [tool.hatch.build.targets.wheel]
59
+ packages = ["src/igaming_market_sdk"]
60
+
61
+ [tool.pytest.ini_options]
62
+ pythonpath = ["src"]
63
+ testpaths = ["tests"]
64
+
65
+ [tool.ruff]
66
+ line-length = 110
67
+ target-version = "py39"
68
+
69
+ [tool.ruff.lint]
70
+ select = ["E4", "E7", "E9", "F"]
@@ -0,0 +1,14 @@
1
+ """Python SDK for the 2WinPower iGaming Market Compliance & Slot Metadata API."""
2
+
3
+ from .client import DEFAULT_BASE_URL, IGamingMarketClient
4
+ from .exceptions import IGamingAPIError, IGamingValidationError
5
+
6
+ __all__ = [
7
+ "DEFAULT_BASE_URL",
8
+ "IGamingMarketClient",
9
+ "IGamingAPIError",
10
+ "IGamingValidationError",
11
+ "__version__",
12
+ ]
13
+
14
+ __version__ = "1.0.0"
@@ -0,0 +1,76 @@
1
+ """Command-line interface for igaming-market-sdk."""
2
+
3
+ import argparse
4
+ import json
5
+ import sys
6
+ from typing import List, Optional
7
+
8
+ from .client import DEFAULT_BASE_URL, IGamingMarketClient
9
+ from .exceptions import IGamingAPIError, IGamingValidationError
10
+
11
+
12
+ def build_parser() -> argparse.ArgumentParser:
13
+ parser = argparse.ArgumentParser(
14
+ prog="igaming-market",
15
+ description="CLI for the 2WinPower iGaming Market Compliance & Slot Metadata API.",
16
+ )
17
+ parser.add_argument(
18
+ "--base-url",
19
+ default=DEFAULT_BASE_URL,
20
+ help=f"API base URL (default: {DEFAULT_BASE_URL})",
21
+ )
22
+ sub = parser.add_subparsers(dest="command", required=True)
23
+
24
+ sub.add_parser("markets", help="List all supported countries")
25
+
26
+ geo_p = sub.add_parser("geo", help="Fetch compliance and payment profile for a country")
27
+ geo_p.add_argument("country", help="ISO-2 country code (e.g. BR, DE, CA)")
28
+
29
+ sub.add_parser("providers", help="List game providers")
30
+
31
+ search_p = sub.add_parser("search", help="Search games by title or provider")
32
+ search_p.add_argument("query", nargs="?", default="", help="Search term (e.g. sweet)")
33
+
34
+ wag_p = sub.add_parser("wagering", help="Calculate bonus wagering turnover and EV")
35
+ wag_p.add_argument("--deposit", type=float, required=True, help="Deposit amount")
36
+ wag_p.add_argument("--bonus", type=float, required=True, help="Bonus amount")
37
+ wag_p.add_argument("--multiplier", type=float, required=True, help="Wagering multiplier")
38
+ wag_p.add_argument("--rtp", type=float, default=96.0, help="Slot RTP percent (default: 96.0)")
39
+
40
+ return parser
41
+
42
+
43
+ def main(argv: Optional[List[str]] = None) -> int:
44
+ parser = build_parser()
45
+ args = parser.parse_args(argv)
46
+
47
+ try:
48
+ with IGamingMarketClient(base_url=args.base_url) as client:
49
+ if args.command == "markets":
50
+ result = client.list_markets()
51
+ elif args.command == "geo":
52
+ result = client.get_geo(args.country)
53
+ elif args.command == "providers":
54
+ result = client.list_providers()
55
+ elif args.command == "search":
56
+ result = client.search_games(args.query)
57
+ elif args.command == "wagering":
58
+ result = client.calculate_wagering(
59
+ deposit_amount=args.deposit,
60
+ bonus_amount=args.bonus,
61
+ wagering_multiplier=args.multiplier,
62
+ slot_rtp_percent=args.rtp,
63
+ )
64
+ else:
65
+ parser.error(f"Unknown command: {args.command}")
66
+ return 2
67
+ except (IGamingValidationError, IGamingAPIError) as exc:
68
+ print(f"Error: {exc}", file=sys.stderr)
69
+ return 1
70
+
71
+ print(json.dumps(result, indent=2, ensure_ascii=False))
72
+ return 0
73
+
74
+
75
+ if __name__ == "__main__":
76
+ raise SystemExit(main())
@@ -0,0 +1,133 @@
1
+ """HTTP client for the 2WinPower public B2B iGaming Market API."""
2
+
3
+ from typing import Any, Dict, Optional
4
+
5
+ import httpx
6
+
7
+ from .exceptions import IGamingAPIError, IGamingValidationError
8
+
9
+ DEFAULT_BASE_URL = "https://api.2wpower.com"
10
+ DEFAULT_TIMEOUT = 15.0
11
+
12
+
13
+ class IGamingMarketClient:
14
+ """Synchronous client for querying https://api.2wpower.com endpoints."""
15
+
16
+ def __init__(
17
+ self,
18
+ base_url: str = DEFAULT_BASE_URL,
19
+ timeout: float = DEFAULT_TIMEOUT,
20
+ transport: Optional[httpx.BaseTransport] = None,
21
+ ) -> None:
22
+ cleaned = base_url.strip().rstrip("/")
23
+ if not cleaned.startswith(("https://", "http://localhost", "http://127.0.0.1")):
24
+ raise IGamingValidationError(
25
+ "base_url must use https:// (http:// is only allowed for localhost)."
26
+ )
27
+ if timeout <= 0:
28
+ raise IGamingValidationError("timeout must be a positive number.")
29
+
30
+ self.base_url = cleaned
31
+ self._client = httpx.Client(
32
+ base_url=self.base_url,
33
+ timeout=timeout,
34
+ transport=transport,
35
+ headers={
36
+ "Accept": "application/json",
37
+ "User-Agent": "igaming-market-sdk/1.0.0 (+https://2wpower.com)",
38
+ },
39
+ )
40
+
41
+ def __enter__(self) -> "IGamingMarketClient":
42
+ return self
43
+
44
+ def __exit__(self, exc_type: Any, exc: Any, tb: Any) -> None:
45
+ self.close()
46
+
47
+ def close(self) -> None:
48
+ """Close the underlying HTTP connection pool."""
49
+ self._client.close()
50
+
51
+ def _request(
52
+ self,
53
+ method: str,
54
+ path: str,
55
+ params: Optional[Dict[str, Any]] = None,
56
+ json_body: Optional[Dict[str, Any]] = None,
57
+ ) -> Any:
58
+ try:
59
+ response = self._client.request(
60
+ method=method,
61
+ url=path,
62
+ params=params,
63
+ json=json_body,
64
+ )
65
+ except httpx.HTTPError as exc:
66
+ raise IGamingAPIError(f"Network error while calling {path}: {exc}") from exc
67
+
68
+ if response.status_code >= 400:
69
+ payload: Any
70
+ try:
71
+ payload = response.json()
72
+ except ValueError:
73
+ payload = response.text
74
+ raise IGamingAPIError(
75
+ message=f"API request failed with HTTP {response.status_code} on {path}",
76
+ status_code=response.status_code,
77
+ payload=payload,
78
+ )
79
+
80
+ try:
81
+ return response.json()
82
+ except ValueError as exc:
83
+ raise IGamingAPIError(
84
+ message=f"Invalid JSON returned by {path}",
85
+ status_code=response.status_code,
86
+ payload=response.text,
87
+ ) from exc
88
+
89
+ def list_markets(self) -> Any:
90
+ """Return the list of supported global iGaming market profiles."""
91
+ return self._request("GET", "/v1/markets")
92
+
93
+ def get_geo(self, country_code: str) -> Dict[str, Any]:
94
+ """Return regulatory compliance, tax, and payment rail data for an ISO-2 country code."""
95
+ code = country_code.strip().upper()
96
+ if len(code) != 2 or not code.isalpha():
97
+ raise IGamingValidationError(
98
+ "country_code must be a 2-letter ISO-3166-1 alpha-2 code (e.g. 'BR', 'DE')."
99
+ )
100
+ return self._request("GET", "/v1/geo", params={"country": code})
101
+
102
+ def list_providers(self) -> Any:
103
+ """Return the directory of supported game studios and provider metadata."""
104
+ return self._request("GET", "/v1/providers")
105
+
106
+ def search_games(self, query: str = "") -> Dict[str, Any]:
107
+ """Search slot and game metadata by title, studio, or category."""
108
+ return self._request("GET", "/v1/games/search", params={"q": query.strip()})
109
+
110
+ def calculate_wagering(
111
+ self,
112
+ deposit_amount: float,
113
+ bonus_amount: float,
114
+ wagering_multiplier: float,
115
+ slot_rtp_percent: float = 96.0,
116
+ ) -> Dict[str, Any]:
117
+ """Calculate total wagering turnover, house edge, theoretical GGR, and expected value."""
118
+ if deposit_amount < 0:
119
+ raise IGamingValidationError("deposit_amount cannot be negative.")
120
+ if bonus_amount < 0:
121
+ raise IGamingValidationError("bonus_amount cannot be negative.")
122
+ if wagering_multiplier <= 0:
123
+ raise IGamingValidationError("wagering_multiplier must be greater than 0.")
124
+ if not (50.0 <= slot_rtp_percent <= 99.99):
125
+ raise IGamingValidationError("slot_rtp_percent must be between 50.0 and 99.99.")
126
+
127
+ payload = {
128
+ "deposit_amount": float(deposit_amount),
129
+ "bonus_amount": float(bonus_amount),
130
+ "wagering_multiplier": float(wagering_multiplier),
131
+ "slot_rtp_percent": float(slot_rtp_percent),
132
+ }
133
+ return self._request("POST", "/v1/calculate/wagering", json_body=payload)
@@ -0,0 +1,22 @@
1
+ """Custom exceptions for igaming-market-sdk."""
2
+
3
+ from typing import Any, Optional
4
+
5
+
6
+ class IGamingAPIError(Exception):
7
+ """Raised when the remote API returns an HTTP error or unreachable response."""
8
+
9
+ def __init__(
10
+ self,
11
+ message: str,
12
+ status_code: Optional[int] = None,
13
+ payload: Optional[Any] = None,
14
+ ) -> None:
15
+ super().__init__(message)
16
+ self.message = message
17
+ self.status_code = status_code
18
+ self.payload = payload
19
+
20
+
21
+ class IGamingValidationError(ValueError):
22
+ """Raised when client input parameters fail local validation."""
@@ -0,0 +1,140 @@
1
+ """Unit tests for IGamingMarketClient using offline httpx.MockTransport."""
2
+
3
+ import json
4
+
5
+ import httpx
6
+ import pytest
7
+
8
+ from igaming_market_sdk import (
9
+ IGamingAPIError,
10
+ IGamingMarketClient,
11
+ IGamingValidationError,
12
+ )
13
+ from igaming_market_sdk.cli import build_parser
14
+
15
+
16
+ def make_mock_client(handler):
17
+ transport = httpx.MockTransport(handler)
18
+ return IGamingMarketClient(transport=transport)
19
+
20
+
21
+ def test_get_geo_normalizes_country_code():
22
+ def handler(request: httpx.Request) -> httpx.Response:
23
+ assert request.method == "GET"
24
+ assert request.url.path == "/v1/geo"
25
+ assert request.url.params["country"] == "BR"
26
+ return httpx.Response(
27
+ 200,
28
+ json={
29
+ "country_code": "BR",
30
+ "country_name": "Brazil",
31
+ "regulation": {"status": "Regulated", "tax_ggr_percent": 12.0},
32
+ },
33
+ )
34
+
35
+ with make_mock_client(handler) as client:
36
+ data = client.get_geo(" br ")
37
+ assert data["country_code"] == "BR"
38
+ assert data["regulation"]["tax_ggr_percent"] == 12.0
39
+
40
+
41
+ def test_get_geo_rejects_invalid_country_code():
42
+ with make_mock_client(lambda r: httpx.Response(200, json={})) as client:
43
+ with pytest.raises(IGamingValidationError):
44
+ client.get_geo("BRA")
45
+ with pytest.raises(IGamingValidationError):
46
+ client.get_geo("12")
47
+
48
+
49
+ def test_list_markets_and_providers():
50
+ def handler(request: httpx.Request) -> httpx.Response:
51
+ if request.url.path == "/v1/markets":
52
+ return httpx.Response(200, json={"total": 40, "items": [{"country_code": "BR"}]})
53
+ if request.url.path == "/v1/providers":
54
+ return httpx.Response(
55
+ 200, json={"total": 15, "items": [{"provider_id": "pragmatic-play"}]}
56
+ )
57
+ return httpx.Response(404, json={"detail": "Not Found"})
58
+
59
+ with make_mock_client(handler) as client:
60
+ markets = client.list_markets()
61
+ providers = client.list_providers()
62
+ assert markets["total"] == 40
63
+ assert providers["total"] == 15
64
+
65
+
66
+ def test_search_games():
67
+ def handler(request: httpx.Request) -> httpx.Response:
68
+ assert request.url.path == "/v1/games/search"
69
+ assert request.url.params["q"] == "sweet"
70
+ return httpx.Response(
71
+ 200,
72
+ json={
73
+ "query": "sweet",
74
+ "total_results": 2,
75
+ "items": [{"game_id": "pragmatic-sweet-bonanza", "title": "Sweet Bonanza"}],
76
+ },
77
+ )
78
+
79
+ with make_mock_client(handler) as client:
80
+ res = client.search_games(" sweet ")
81
+ assert res["total_results"] == 2
82
+ assert res["items"][0]["title"] == "Sweet Bonanza"
83
+
84
+
85
+ def test_calculate_wagering_payload_and_response():
86
+ def handler(request: httpx.Request) -> httpx.Response:
87
+ assert request.method == "POST"
88
+ assert request.url.path == "/v1/calculate/wagering"
89
+ body = json.loads(request.content.decode("utf-8"))
90
+ assert body == {
91
+ "deposit_amount": 100.0,
92
+ "bonus_amount": 100.0,
93
+ "wagering_multiplier": 35.0,
94
+ "slot_rtp_percent": 96.2,
95
+ }
96
+ return httpx.Response(200, json={"total_turnover": 3500.0, "expected_value": -33.0})
97
+
98
+ with make_mock_client(handler) as client:
99
+ res = client.calculate_wagering(100, 100, 35, 96.2)
100
+ assert res["total_turnover"] == 3500.0
101
+
102
+
103
+ def test_calculate_wagering_validation():
104
+ with make_mock_client(lambda r: httpx.Response(200, json={})) as client:
105
+ with pytest.raises(IGamingValidationError):
106
+ client.calculate_wagering(-10, 100, 35, 96.0)
107
+ with pytest.raises(IGamingValidationError):
108
+ client.calculate_wagering(100, 100, 0, 96.0)
109
+ with pytest.raises(IGamingValidationError):
110
+ client.calculate_wagering(100, 100, 35, 105.0)
111
+
112
+
113
+ def test_http_error_raises_api_error():
114
+ def handler(request: httpx.Request) -> httpx.Response:
115
+ return httpx.Response(404, json={"detail": "Country not found"})
116
+
117
+ with make_mock_client(handler) as client:
118
+ with pytest.raises(IGamingAPIError) as exc_info:
119
+ client.get_geo("ZZ")
120
+ assert exc_info.value.status_code == 404
121
+ assert exc_info.value.payload == {"detail": "Country not found"}
122
+
123
+
124
+ def test_non_https_base_url_rejected():
125
+ with pytest.raises(IGamingValidationError):
126
+ IGamingMarketClient(base_url="http://example.com")
127
+
128
+
129
+ def test_cli_parser_commands():
130
+ parser = build_parser()
131
+ args = parser.parse_args(["geo", "BR"])
132
+ assert args.command == "geo"
133
+ assert args.country == "BR"
134
+
135
+ w_args = parser.parse_args(
136
+ ["wagering", "--deposit", "100", "--bonus", "50", "--multiplier", "30", "--rtp", "96.5"]
137
+ )
138
+ assert w_args.command == "wagering"
139
+ assert w_args.deposit == 100.0
140
+ assert w_args.rtp == 96.5