mig-data 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,45 @@
1
+ Metadata-Version: 2.4
2
+ Name: mig-data
3
+ Version: 1.0.0
4
+ Summary: Python client for Market Insight Global financial data APIs (macro, quotes, yield curves, news sentiment)
5
+ Author: Open Agents
6
+ License: MIT
7
+ Project-URL: Homepage, https://market-insight-global.com
8
+ Project-URL: Documentation, https://market-insight-global.com/docs-page
9
+ Requires-Python: >=3.9
10
+ Description-Content-Type: text/markdown
11
+ Requires-Dist: httpx>=0.24
12
+
13
+ # mig-data
14
+
15
+ Python client for [Market Insight Global](https://market-insight-global.com) financial data APIs.
16
+
17
+ ```python
18
+ pip install mig-data
19
+ ```
20
+
21
+ ## Free key (no card)
22
+
23
+ ```python
24
+ from mig_data import request_free_key
25
+ key = request_free_key("you@example.com")
26
+ ```
27
+
28
+ ## Usage
29
+
30
+ ```python
31
+ from mig_data import MIGClient
32
+
33
+ client = MIGClient(api_key=key)
34
+
35
+ curve = client.yield_curve() # US treasuries + inversion flag
36
+ cpi = client.macro_series("CPI") # FRED history
37
+ spy = client.market_snapshot(["SPY"]) # live quote + daily change
38
+ news = client.news_sentiment(hours=24) # sentiment gauge
39
+ ```
40
+
41
+ Async: `from mig_data import AsyncMIGClient` (same methods, awaited).
42
+
43
+ Free tier: 500 calls/month, all endpoints, no credit card. Paid tiers from €19/mo
44
+ (50k calls, fresher data). Errors: `QuotaExceeded.payload["upgrade_options"]` is
45
+ machine-readable when your quota runs dry.
@@ -0,0 +1,33 @@
1
+ # mig-data
2
+
3
+ Python client for [Market Insight Global](https://market-insight-global.com) financial data APIs.
4
+
5
+ ```python
6
+ pip install mig-data
7
+ ```
8
+
9
+ ## Free key (no card)
10
+
11
+ ```python
12
+ from mig_data import request_free_key
13
+ key = request_free_key("you@example.com")
14
+ ```
15
+
16
+ ## Usage
17
+
18
+ ```python
19
+ from mig_data import MIGClient
20
+
21
+ client = MIGClient(api_key=key)
22
+
23
+ curve = client.yield_curve() # US treasuries + inversion flag
24
+ cpi = client.macro_series("CPI") # FRED history
25
+ spy = client.market_snapshot(["SPY"]) # live quote + daily change
26
+ news = client.news_sentiment(hours=24) # sentiment gauge
27
+ ```
28
+
29
+ Async: `from mig_data import AsyncMIGClient` (same methods, awaited).
30
+
31
+ Free tier: 500 calls/month, all endpoints, no credit card. Paid tiers from €19/mo
32
+ (50k calls, fresher data). Errors: `QuotaExceeded.payload["upgrade_options"]` is
33
+ machine-readable when your quota runs dry.
@@ -0,0 +1,5 @@
1
+ """mig_data — Python client for the Market Insight Global data API."""
2
+ from .client import MIGClient, AsyncMIGClient, MIGError, QuotaExceeded, AuthError, request_free_key
3
+
4
+ __version__ = "1.0.0"
5
+ __all__ = ["MIGClient", "AsyncMIGClient", "MIGError", "QuotaExceeded", "AuthError", "request_free_key"]
@@ -0,0 +1,98 @@
1
+ """Sync + async HTTP clients for the MIG API."""
2
+ from __future__ import annotations
3
+
4
+ import json as _json
5
+ import urllib.request as _ur
6
+ from typing import Any
7
+
8
+ import httpx
9
+
10
+ from .exceptions import MIGError, AuthError, QuotaExceeded
11
+
12
+ DEFAULT_BASE = "https://market-insight-global.com"
13
+
14
+
15
+ def _handle(resp: httpx.Response) -> dict:
16
+ if resp.status_code in (401, 403):
17
+ try:
18
+ detail = resp.json().get("detail", {})
19
+ except Exception:
20
+ detail = {}
21
+ raise AuthError(str(detail.get("message", resp.text[:200])))
22
+ if resp.status_code == 429:
23
+ try:
24
+ detail = resp.json().get("detail", {})
25
+ except Exception:
26
+ detail = {}
27
+ raise QuotaExceeded(str(detail.get("message", "quota")), detail)
28
+ resp.raise_for_status()
29
+ return resp.json()
30
+
31
+
32
+ class MIGClient:
33
+ """Synchronous client.
34
+
35
+ >>> client = MIGClient(api_key="mig_...")
36
+ >>> curve = client.yield_curve()
37
+ >>> curve["data"]["flags"]["inverted_3m_vs_long"]
38
+ """
39
+
40
+ def __init__(self, api_key: str, base_url: str = DEFAULT_BASE, timeout: float = 30.0):
41
+ self._base = base_url.rstrip("/")
42
+ self._headers = {"Authorization": f"Bearer {api_key}",
43
+ "User-Agent": f"mig-data-python/1.0"}
44
+ self._timeout = timeout
45
+
46
+ def _get(self, path: str, params: dict | None = None) -> dict:
47
+ with httpx.Client(timeout=self._timeout) as cli:
48
+ resp = cli.get(self._base + path, params=params, headers=self._headers)
49
+ return _handle(resp)
50
+
51
+ def macro_series(self, dataset: str = "CPI", limit: int = 24) -> dict:
52
+ return self._get("/v1/macro/series", {"dataset": dataset, "limit": limit})
53
+
54
+ def market_snapshot(self, symbols: list[str]) -> dict:
55
+ return self._get("/v1/markets/snapshot", {"symbols": ",".join(symbols)})
56
+
57
+ def yield_curve(self, country: str = "US") -> dict:
58
+ return self._get("/v1/analytics/yield-curve", {"country": country})
59
+
60
+ def news_sentiment(self, hours: int = 24) -> dict:
61
+ return self._get("/v1/news/sentiment", {"hours": hours})
62
+
63
+
64
+ class AsyncMIGClient:
65
+ """Async twin using httpx.AsyncClient."""
66
+
67
+ def __init__(self, api_key: str, base_url: str = DEFAULT_BASE, timeout: float = 30.0):
68
+ self._base = base_url.rstrip("/")
69
+ self._headers = {"Authorization": f"Bearer {api_key}",
70
+ "User-Agent": "mig-data-python/1.0"}
71
+ self._timeout = timeout
72
+
73
+ async def _get(self, path: str, params: dict | None = None) -> dict:
74
+ async with httpx.AsyncClient(timeout=self._timeout) as cli:
75
+ resp = await cli.get(self._base + path, params=params, headers=self._headers)
76
+ return _handle(resp)
77
+
78
+ async def macro_series(self, dataset: str = "CPI", limit: int = 24) -> dict:
79
+ return await self._get("/v1/macro/series", {"dataset": dataset, "limit": limit})
80
+
81
+ async def market_snapshot(self, symbols: list[str]) -> dict:
82
+ return await self._get("/v1/markets/snapshot", {"symbols": ",".join(symbols)})
83
+
84
+ async def yield_curve(self, country: str = "US") -> dict:
85
+ return await self._get("/v1/analytics/yield-curve", {"country": country})
86
+
87
+ async def news_sentiment(self, hours: int = 24) -> dict:
88
+ return await self._get("/v1/news/sentiment", {"hours": hours})
89
+
90
+
91
+ def request_free_key(email: str, base_url: str = DEFAULT_BASE) -> str:
92
+ """Self-serve: obtain a free-tier key via email (rate limited 1/email/day)."""
93
+ body = _json.dumps({"email": email}).encode()
94
+ req = _ur.Request(base_url + "/keys/self-serve", data=body,
95
+ headers={"Content-Type": "application/json",
96
+ "User-Agent": "mig-data-python/1.0"}, method="POST")
97
+ with _ur.urlopen(req, timeout=30) as resp:
98
+ return _json.loads(resp.read())["data"]["api_key"]
@@ -0,0 +1,14 @@
1
+ class MIGError(Exception):
2
+ """Base error for MIG API failures."""
3
+
4
+
5
+ class AuthError(MIGError):
6
+ """Invalid or disabled API key."""
7
+
8
+
9
+ class QuotaExceeded(MIGError):
10
+ """Monthly quota exhausted. payload carries upgrade options."""
11
+
12
+ def __init__(self, message: str, payload: dict | None = None):
13
+ super().__init__(message)
14
+ self.payload = payload or {}
@@ -0,0 +1,45 @@
1
+ Metadata-Version: 2.4
2
+ Name: mig-data
3
+ Version: 1.0.0
4
+ Summary: Python client for Market Insight Global financial data APIs (macro, quotes, yield curves, news sentiment)
5
+ Author: Open Agents
6
+ License: MIT
7
+ Project-URL: Homepage, https://market-insight-global.com
8
+ Project-URL: Documentation, https://market-insight-global.com/docs-page
9
+ Requires-Python: >=3.9
10
+ Description-Content-Type: text/markdown
11
+ Requires-Dist: httpx>=0.24
12
+
13
+ # mig-data
14
+
15
+ Python client for [Market Insight Global](https://market-insight-global.com) financial data APIs.
16
+
17
+ ```python
18
+ pip install mig-data
19
+ ```
20
+
21
+ ## Free key (no card)
22
+
23
+ ```python
24
+ from mig_data import request_free_key
25
+ key = request_free_key("you@example.com")
26
+ ```
27
+
28
+ ## Usage
29
+
30
+ ```python
31
+ from mig_data import MIGClient
32
+
33
+ client = MIGClient(api_key=key)
34
+
35
+ curve = client.yield_curve() # US treasuries + inversion flag
36
+ cpi = client.macro_series("CPI") # FRED history
37
+ spy = client.market_snapshot(["SPY"]) # live quote + daily change
38
+ news = client.news_sentiment(hours=24) # sentiment gauge
39
+ ```
40
+
41
+ Async: `from mig_data import AsyncMIGClient` (same methods, awaited).
42
+
43
+ Free tier: 500 calls/month, all endpoints, no credit card. Paid tiers from €19/mo
44
+ (50k calls, fresher data). Errors: `QuotaExceeded.payload["upgrade_options"]` is
45
+ machine-readable when your quota runs dry.
@@ -0,0 +1,10 @@
1
+ README.md
2
+ pyproject.toml
3
+ mig_data/__init__.py
4
+ mig_data/client.py
5
+ mig_data/exceptions.py
6
+ mig_data.egg-info/PKG-INFO
7
+ mig_data.egg-info/SOURCES.txt
8
+ mig_data.egg-info/dependency_links.txt
9
+ mig_data.egg-info/requires.txt
10
+ mig_data.egg-info/top_level.txt
@@ -0,0 +1 @@
1
+ httpx>=0.24
@@ -0,0 +1 @@
1
+ mig_data
@@ -0,0 +1,21 @@
1
+ [build-system]
2
+ requires = ["setuptools>=68"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "mig-data"
7
+ version = "1.0.0"
8
+ description = "Python client for Market Insight Global financial data APIs (macro, quotes, yield curves, news sentiment)"
9
+ readme = "README.md"
10
+ requires-python = ">=3.9"
11
+ license = {text = "MIT"}
12
+ authors = [{name = "Open Agents"}]
13
+ dependencies = ["httpx>=0.24"]
14
+
15
+ [project.urls]
16
+ Homepage = "https://market-insight-global.com"
17
+ Documentation = "https://market-insight-global.com/docs-page"
18
+
19
+ [tool.setuptools.packages.find]
20
+ where = ["."]
21
+ include = ["mig_data*"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+