izko-gold-price-api
Flask REST API and Python package that scrapes live gold and currency rates from the Izmir Jewelers Chamber (izko.org.tr) using headless Chromium via Playwright.
Table of Contents
- System Architecture
- Installation from PyPI
- Quick Start: Docker
- Manual Local Setup
- Command-Line Interface
- Model Context Protocol Server
- Python Library Usage
- API Endpoints
- Configuration
- Building and Publishing to PyPI
- Repository Layout
- Testing and Verification
- Contributing and Security
- License
System Architecture
The package exposes both a Python API (izko_gold_price_api) and a Flask server entry point (izko-gold-price-api). When /izko/bundle or scrape() is called, scrape.py launches a headless Chromium instance through Playwright, waits for the price table DOM selector #ataLabel to populate on https://www.izko.org.tr/Home/GuncelKur, extracts each configured element ID, and normalizes Turkish formatted decimals into IEEE 754 floating-point numbers.
sequenceDiagram
participant Client as HTTP Client / Python Caller
participant Flask as Flask Server: izko_gold_price_api.app
participant Scraper as Playwright Scraper: izko_gold_price_api.scrape
participant IZKO as izko.org.tr/Home/GuncelKur
Client->>Flask: GET /izko/bundle
Flask->>Scraper: scrape()
Scraper->>IZKO: page.goto(url)
IZKO-->>Scraper: HTML + dynamic DOM labels
Scraper->>Scraper: wait_for_selector(#ataLabel)
Scraper->>Scraper: Extract inner_text and convert via to_float()
Scraper-->>Flask: dict payload, HTTP 200
Flask-->>Client: application/json
Installation from PyPI
Install the package and download the Playwright Chromium binary:
pip install izko-gold-price-api
playwright install chromium
# Start the Flask REST API server
izko-gold-price-api
Quick Start: Docker
Run the service in an isolated container with Chromium and system libraries pre-installed.
# 1. Clone the repository
git clone https://github.com/AtaCanYmc/izko-gold-price-api.git && cd izko-gold-price-api
# 2. Build and start the container
make docker-build
make docker-run
# 3. Verify service metadata endpoint
curl -f http://localhost:5000/izko
Manual Local Setup
Install the package in editable mode on macOS, Linux, or Windows with Python 3.10 or newer.
# 1. Create and activate a virtual environment
python3 -m venv venv
source venv/bin/activate
# 2. Install package in editable mode and download Chromium binary
make install
# 3. Start the Flask server via CLI entry point
make run
Command-Line Interface
The izko-gold-price-api command and python -m izko_gold_price_api module entry point are implemented in cli.py with three subcommands: serve, scrape, and config.
# Start Flask server on custom host and port with debug disabled
izko-gold-price-api serve --host 0.0.0.0 --port 8080 --no-debug
# Scrape live rates once and pretty-print JSON to stdout
izko-gold-price-api scrape --pretty
# Query a single price field for shell pipelines
izko-gold-price-api scrape --field GramAltin
# Print active configuration JSON
izko-gold-price-api config
| Subcommand / Flag | Short | Type | Default | Description |
|---|---|---|---|---|
--version |
-V |
Flag | false |
Print package version and exit. |
--config |
-c |
Path | Bundled config.json |
Override path to config.json. |
serve --host |
None | String | 127.0.0.1 |
Override Flask bind host. |
serve --port |
None | Integer | 5000 |
Override Flask listener port. |
serve --debug / --no-debug |
None | Boolean | false |
Enable or disable Flask debug mode. |
scrape --field |
-f |
String | None | Output a single field from priceList. |
scrape --pretty |
None | Flag | false |
Format JSON output with 2-space indentation. |
scrape --url |
None | String | url.izko |
Override target URL for a single run. |
scrape --timeout |
None | Integer | 10000 |
Override selector wait timeout in milliseconds. |
config |
None | Subcommand | None | Print active configuration JSON and exit. |
mcp |
None | Subcommand | None | Start the MCP JSON-RPC 2.0 server over stdio. |
Model Context Protocol Server
The package includes a zero-dependency Model Context Protocol (MCP) JSON-RPC 2.0 stdio server in mcp.py. Launch it via izko-gold-price-mcp or izko-gold-price-api mcp.
{
"mcpServers": {
"izko-gold-price": {
"command": "izko-gold-price-mcp"
}
}
}
| MCP Capability | Name / URI | Description |
|---|---|---|
| Tool | get_izko_prices |
Scrapes live IZKO gold and currency rates. Accepts optional field and timeout arguments. |
| Tool | get_izko_config |
Returns active URL, selector timeout, DOM label IDs, and API configuration. |
| Resource | izko://config |
Active configuration JSON document. |
| Resource | izko://prices |
Live scraped price bundle JSON document. |
Python Library Usage
Import scrape, to_float, or the Flask app instance directly in Python code:
from izko_gold_price_api import scrape, to_float
payload, status_code = scrape()
if status_code == 200:
print(payload["priceList"]["GramAltin"])
API Endpoints
GET /izko
Returns the active server configuration and registered route paths from config.json.
curl -s http://127.0.0.1:5000/izko
Response (200 OK):
{
"debug": false,
"endpointList": {
"base": "/izko",
"bundle": "/izko/bundle"
},
"host": "127.0.0.1",
"port": 5000,
"rootMessage": "Welcome to izko API"
}
GET /izko/bundle
Executes a live headless Chromium scrape against the configured IZKO URL and returns parsed quotes. Numeric strings with Turkish thousand separators . and decimal commas , are converted to floats. Non-numeric values such as the timestamp string remain strings.
curl -s http://127.0.0.1:5000/izko/bundle
Response (200 OK):
{
"priceList": {
"14Ayar": 2150.0,
"18Ayar": 2580.0,
"22Ayar": 3180.0,
"Ceyrek": 5720.0,
"Cumhuriyet": 23450.0,
"Dolar": 34.25,
"Euro": 37.1,
"GramAltin": 3180.0,
"PaketliHas": 3505.0,
"Tarih": "14:30:00",
"Yarim": 11440.0,
"Ziynet": 22880.0
},
"url": "https://www.izko.org.tr/Home/GuncelKur"
}
Configuration
Default runtime settings live in src/izko_gold_price_api/config.json. Set the IZKO_CONFIG_PATH environment variable to point to an external JSON file when overriding defaults without modifying the installed package.
Server and Scraper Parameters
| Key Path | Env Override | Type | Default | Required | Description |
|---|---|---|---|---|---|
url.izko |
None | String | https://www.izko.org.tr/Home/GuncelKur |
Yes | Target URL scraped by Playwright. |
url.timeout |
IZKO_TIMEOUT |
Integer | 10000 |
Yes | Selector wait timeout in milliseconds. |
url.cache_ttl |
IZKO_CACHE_TTL |
Integer | 30 |
No | In-memory response cache TTL in seconds (0 disables cache). |
api.host |
IZKO_HOST |
String | 127.0.0.1 |
Yes | Flask bind address. Set to 0.0.0.0 inside Docker containers. |
api.port |
IZKO_PORT |
Integer | 5000 |
Yes | HTTP listener port. |
api.debug |
IZKO_DEBUG |
Boolean | false |
Yes | Enables Flask debug reloader. Keep false in production. |
api.rootMessage |
None | String | Welcome to izko API |
No | Informational message returned by /izko. |
DOM Selector Mapping (label)
| Output Field | Target DOM ID | Asset Type |
|---|---|---|
22Ayar |
#yirmiikiLabel |
22 Karat gold price |
18Ayar |
#onsekizLabel |
18 Karat gold price |
14Ayar |
#ondortLabel |
14 Karat gold price |
GramAltin |
#gramLabel |
24 Karat gram gold price |
Cumhuriyet |
#ataLabel |
Cumhuriyet gold coin price and readiness anchor |
Ceyrek |
#yeniceyrekLabel |
Quarter gold coin price |
Yarim |
#yeniyarimLabel |
Half gold coin price |
Ziynet |
#yenitamLabel |
Full Ziynet gold coin price |
PaketliHas |
#ons |
Packaged fine gold / ounce indicator |
Dolar |
#dolar |
USD/TRY exchange rate |
Euro |
#euro |
EUR/TRY exchange rate |
Tarih |
#clock |
Source update timestamp |
Building and Publishing to PyPI
Every merged Release Please pull request automatically builds sdist and bdist_wheel distributions and publishes them to PyPI using OpenID Connect (OIDC) Trusted Publishing (pypa/gh-action-pypi-publish@release/v1) under the pypi GitHub Actions environment.
To build and verify distributions locally:
make build
make publish
Repository Layout
.
├── .github/
│ ├── CODEOWNERS
│ ├── ISSUE_TEMPLATE/
│ │ ├── bug_report.yml
│ │ ├── config.yaml
│ │ └── feature_request.yml
│ ├── PULL_REQUEST_TEMPLATE/
│ │ └── pull_request_template.md
│ ├── dependabot.yml
│ └── workflows/
│ ├── ci.yml
│ └── release-please.yml
├── .dockerignore
├── .editorconfig
├── .gitattributes
├── .gitignore
├── .markdownlint.json
├── .release-please-manifest.json
├── CHANGELOG.md
├── CONTRIBUTING.md
├── Dockerfile
├── LICENSE
├── Makefile
├── README.md
├── README.tr.md
├── ROADMAP.md
├── SECURITY.md
├── docs/
│ ├── README.md
│ ├── api-reference.md
│ ├── architecture.md
│ ├── cli-and-mcp.md
│ └── deployment.md
├── pyproject.toml
├── release-please-config.json
├── requirements.txt
└── src/
└── izko_gold_price_api/
├── __init__.py
├── __main__.py
├── app.py
├── cli.py
├── config.json
├── mcp.py
└── scrape.py
Testing and Verification
Validate configuration syntax, Python bytecode compilation, and documentation links locally before opening a pull request:
# Run syntax, config schema, and markdown link verification
make verify
# Verify Turkish decimal normalization logic (with virtualenv active)
python -c "from izko_gold_price_api import to_float; assert to_float('23.450,75') == 23450.75; assert to_float('14:30') == '14:30'"
Contributing and Security
- Extended technical guides live in docs/README.md.
- Contribution workflow and commit conventions are documented in CONTRIBUTING.md.
- Planned technical milestones are tracked in ROADMAP.md.
- Vulnerability disclosure steps are specified in SECURITY.md.
License
Released under the MIT License.
Metadata
Release files for izko-gold-price-api 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| izko_gold_price_api-0.2.0.tar.gz | 17.2 kB | With provenance | Details for izko_gold_price_api-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| izko_gold_price_api-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for izko_gold_price_api-0.2.0-py3-none-any.whl |
Total release size: 32.4 kB
Release files / izko_gold_price_api-0.2.0.tar.gz
| Download URL | izko_gold_price_api-0.2.0.tar.gz |
|---|---|
| Size | 17.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
845b2128748b77aafa7f29b3eb535e8213a62d47491fce8599b999e0ca297375
|
|
BLAKE2b-256 checksum How to use checksums |
71d44ef4309ed50bb6fa5f79c55900d946887dedee54445393eac8129e3a74b1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 21, 2026.
Transparency logRelease files / izko_gold_price_api-0.2.0-py3-none-any.whl
| Download URL | izko_gold_price_api-0.2.0-py3-none-any.whl |
|---|---|
| Size | 15.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f0ad7d6933f480d604a0955d5fb8d180d0c54525c799248bcd6ab65c2d3c7a30
|
|
BLAKE2b-256 checksum How to use checksums |
ea2a8283171205a5fd0110618b37216672d347a8316cb7d19dbb264ea938b1df
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 21, 2026.
Transparency logSecurity for izko-gold-price-api 0.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for izko_gold_price_api-0.2.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 21, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.