crawlora-bbb 0.1.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,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Crawlora
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,99 @@
1
+ Metadata-Version: 2.4
2
+ Name: crawlora-bbb
3
+ Version: 0.1.0
4
+ Summary: Typed Better Business Bureau client for the Crawlora hosted API
5
+ Author: Crawlora
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/Crawlora-org/crawlora-bbb
8
+ Project-URL: Repository, https://github.com/Crawlora-org/crawlora-bbb
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: Programming Language :: Python :: 3.10
11
+ Classifier: Typing :: Typed
12
+ Requires-Python: >=3.10
13
+ Description-Content-Type: text/markdown
14
+ License-File: LICENSE
15
+ Requires-Dist: typing-extensions>=4.7; python_version < "3.11"
16
+ Provides-Extra: async
17
+ Requires-Dist: httpx>=0.27; extra == "async"
18
+ Provides-Extra: test
19
+ Requires-Dist: mypy>=1.11; extra == "test"
20
+ Requires-Dist: pytest>=8; extra == "test"
21
+ Dynamic: license-file
22
+
23
+ # crawlora-bbb
24
+
25
+ Python client for Crawlora's hosted Better Business Bureau API. It calls Crawlora's
26
+ service at [Crawlora](https://crawlora.net); it does not run a browser or scrape
27
+ Better Business Bureau locally. A Crawlora account and `CRAWLORA_API_KEY` are required,
28
+ and API use is billed under your Crawlora account. Crawlora is independent from and not endorsed by
29
+ Better Business Bureau or its owners.
30
+
31
+ ## Install
32
+
33
+ ```sh
34
+ python -m pip install crawlora-bbb
35
+ ```
36
+
37
+ ## Get an API key
38
+
39
+ Create an account at [crawlora.net](https://crawlora.net/signup), then open the [Crawlora console](https://crawlora.net/app) for API-key setup. Set your key in the shell before running the client:
40
+
41
+ ```sh
42
+ export CRAWLORA_API_KEY="your-crawlora-api-key"
43
+ ```
44
+
45
+ ## Use
46
+
47
+ Save this example as `example.py`, then run `python example.py` after installing the package and setting your API key.
48
+
49
+ ```python
50
+ import os
51
+
52
+ from crawlora_bbb import BBBClient
53
+
54
+ api_key = os.environ.get("CRAWLORA_API_KEY")
55
+ if not api_key:
56
+ raise RuntimeError("Set CRAWLORA_API_KEY before running this example.")
57
+
58
+ with BBBClient(api_key=api_key) as client:
59
+ result_1 = client.search(query='coffee', location='New York, NY')
60
+ print(result_1)
61
+ result_2 = client.business(url='https://www.bbb.org/us/tx/austin/profile/plumber/calixto-plumbing-0825-1000223803')
62
+ print(result_2)
63
+ result_3 = client.scamtracker_search(query='package delivery', state='NY')
64
+ print(result_3)
65
+ ```
66
+
67
+ The package also exports `Client` as an alias for `BBBClient`. Operation
68
+ methods are available directly in snake_case and through the `bbb`
69
+ group. The async package client is `AsyncBBBClient`; see the [online
70
+ endpoint and parameter reference](https://github.com/Crawlora-org/crawlora-bbb/blob/main/docs/usage.md) and [runnable example](https://github.com/Crawlora-org/crawlora-bbb/blob/main/examples/python.py).
71
+
72
+ ### Async usage
73
+
74
+ The package also exports `AsyncClient` for asynchronous requests:
75
+
76
+ ```python
77
+ import asyncio
78
+ import os
79
+
80
+ from crawlora_bbb import AsyncClient
81
+
82
+ async def main():
83
+ api_key = os.environ.get("CRAWLORA_API_KEY")
84
+ if not api_key:
85
+ raise RuntimeError("Set CRAWLORA_API_KEY before running this example.")
86
+ async with AsyncClient(api_key=api_key) as client:
87
+ result_1 = await client.search(query='coffee', location='New York, NY')
88
+ print(result_1)
89
+
90
+ asyncio.run(main())
91
+ ```
92
+
93
+ See the [runnable example](https://github.com/Crawlora-org/crawlora-bbb/blob/main/examples/python.py) for a complete usage example.
94
+
95
+ ## Configuration
96
+
97
+ Pass your key through `api_key` or read `CRAWLORA_API_KEY` from the environment.
98
+ Keep credentials out of source control and logs. Requests go to Crawlora's
99
+ hosted API.
@@ -0,0 +1,77 @@
1
+ # crawlora-bbb
2
+
3
+ Python client for Crawlora's hosted Better Business Bureau API. It calls Crawlora's
4
+ service at [Crawlora](https://crawlora.net); it does not run a browser or scrape
5
+ Better Business Bureau locally. A Crawlora account and `CRAWLORA_API_KEY` are required,
6
+ and API use is billed under your Crawlora account. Crawlora is independent from and not endorsed by
7
+ Better Business Bureau or its owners.
8
+
9
+ ## Install
10
+
11
+ ```sh
12
+ python -m pip install crawlora-bbb
13
+ ```
14
+
15
+ ## Get an API key
16
+
17
+ Create an account at [crawlora.net](https://crawlora.net/signup), then open the [Crawlora console](https://crawlora.net/app) for API-key setup. Set your key in the shell before running the client:
18
+
19
+ ```sh
20
+ export CRAWLORA_API_KEY="your-crawlora-api-key"
21
+ ```
22
+
23
+ ## Use
24
+
25
+ Save this example as `example.py`, then run `python example.py` after installing the package and setting your API key.
26
+
27
+ ```python
28
+ import os
29
+
30
+ from crawlora_bbb import BBBClient
31
+
32
+ api_key = os.environ.get("CRAWLORA_API_KEY")
33
+ if not api_key:
34
+ raise RuntimeError("Set CRAWLORA_API_KEY before running this example.")
35
+
36
+ with BBBClient(api_key=api_key) as client:
37
+ result_1 = client.search(query='coffee', location='New York, NY')
38
+ print(result_1)
39
+ result_2 = client.business(url='https://www.bbb.org/us/tx/austin/profile/plumber/calixto-plumbing-0825-1000223803')
40
+ print(result_2)
41
+ result_3 = client.scamtracker_search(query='package delivery', state='NY')
42
+ print(result_3)
43
+ ```
44
+
45
+ The package also exports `Client` as an alias for `BBBClient`. Operation
46
+ methods are available directly in snake_case and through the `bbb`
47
+ group. The async package client is `AsyncBBBClient`; see the [online
48
+ endpoint and parameter reference](https://github.com/Crawlora-org/crawlora-bbb/blob/main/docs/usage.md) and [runnable example](https://github.com/Crawlora-org/crawlora-bbb/blob/main/examples/python.py).
49
+
50
+ ### Async usage
51
+
52
+ The package also exports `AsyncClient` for asynchronous requests:
53
+
54
+ ```python
55
+ import asyncio
56
+ import os
57
+
58
+ from crawlora_bbb import AsyncClient
59
+
60
+ async def main():
61
+ api_key = os.environ.get("CRAWLORA_API_KEY")
62
+ if not api_key:
63
+ raise RuntimeError("Set CRAWLORA_API_KEY before running this example.")
64
+ async with AsyncClient(api_key=api_key) as client:
65
+ result_1 = await client.search(query='coffee', location='New York, NY')
66
+ print(result_1)
67
+
68
+ asyncio.run(main())
69
+ ```
70
+
71
+ See the [runnable example](https://github.com/Crawlora-org/crawlora-bbb/blob/main/examples/python.py) for a complete usage example.
72
+
73
+ ## Configuration
74
+
75
+ Pass your key through `api_key` or read `CRAWLORA_API_KEY` from the environment.
76
+ Keep credentials out of source control and logs. Requests go to Crawlora's
77
+ hosted API.
@@ -0,0 +1,18 @@
1
+ """Typed Better Business Bureau client for the Crawlora hosted API."""
2
+
3
+ from .platform import BBBClient, AsyncBBBClient
4
+ from .client import CrawloraClientError, CrawloraError, CrawloraNetworkError, CrawloraServerError
5
+ from .operations import OPERATION_COUNT, OPERATION_IDS, PLATFORM
6
+
7
+ Client = BBBClient
8
+ AsyncClient = AsyncBBBClient
9
+ __version__ = '0.1.0'
10
+ DISPLAY_NAME = 'Better Business Bureau'
11
+ PLATFORM = 'bbb'
12
+ CONTRACT_REVISION = 'sha256:c4cf6f235ba96193e786f97a88b354660c07e34d9ae86429136e17dacb7efd48'
13
+
14
+ __all__ = [
15
+ "BBBClient", "AsyncBBBClient", "Client", "AsyncClient",
16
+ "CrawloraError", "CrawloraClientError", "CrawloraServerError", "CrawloraNetworkError",
17
+ "DISPLAY_NAME", "PLATFORM", "CONTRACT_REVISION", "OPERATION_COUNT", "OPERATION_IDS", "__version__",
18
+ ]
@@ -0,0 +1,10 @@
1
+ from .platform import BBBClient as BBBClient
2
+ from .platform import AsyncBBBClient as AsyncBBBClient
3
+ Client = BBBClient
4
+ AsyncClient = AsyncBBBClient
5
+ from .client import CrawloraClientError as CrawloraClientError, CrawloraError as CrawloraError, CrawloraNetworkError as CrawloraNetworkError, CrawloraServerError as CrawloraServerError
6
+ from .operations import OPERATION_COUNT as OPERATION_COUNT, OPERATION_IDS as OPERATION_IDS, PLATFORM as PLATFORM
7
+ __version__: str
8
+ DISPLAY_NAME: str
9
+ CONTRACT_REVISION: str
10
+ __all__ = ['BBBClient', 'AsyncBBBClient', 'Client', 'AsyncClient', 'CrawloraError', 'CrawloraClientError', 'CrawloraServerError', 'CrawloraNetworkError', 'DISPLAY_NAME', 'PLATFORM', 'CONTRACT_REVISION', 'OPERATION_COUNT', 'OPERATION_IDS', '__version__']
@@ -0,0 +1,44 @@
1
+ """Shared pagination helpers used by the sync and async clients.
2
+
3
+ This module deliberately has no `.pyi` stub so type checkers read its inline
4
+ annotations directly (the `client.pyi` stub shadows `client.py`).
5
+ """
6
+
7
+ from __future__ import annotations
8
+
9
+ from typing import Any, Mapping
10
+
11
+ PAGE_PARAM_NAMES = ("page", "offset")
12
+
13
+
14
+ def detect_page_param(operation: Mapping[str, Any]) -> str | None:
15
+ names = {parameter["name"] for parameter in operation.get("queryParams", [])}
16
+ for candidate in PAGE_PARAM_NAMES:
17
+ if candidate in names:
18
+ return candidate
19
+ return None
20
+
21
+
22
+ def page_is_empty(response: Any) -> bool:
23
+ data = response
24
+ if isinstance(response, Mapping) and "data" in response:
25
+ data = response["data"]
26
+ if data is None:
27
+ return True
28
+ if isinstance(data, (list, tuple, dict, str)):
29
+ return len(data) == 0
30
+ return not data
31
+
32
+
33
+ def default_start(page_param: str) -> int:
34
+ return 0 if page_param == "offset" else 1
35
+
36
+
37
+ def default_items(response: Any) -> list[Any]:
38
+ """Default item extractor: the response's ``data`` list (Crawlora envelope),
39
+ or the response itself when it is already a list."""
40
+ if isinstance(response, Mapping) and isinstance(response.get("data"), list):
41
+ return list(response["data"])
42
+ if isinstance(response, list):
43
+ return list(response)
44
+ return []
@@ -0,0 +1,114 @@
1
+ """Keep-alive HTTP transport for the synchronous client (standard library only).
2
+
3
+ Maintains a small pool of reusable connections per ``(scheme, host, port)`` so
4
+ the sync client avoids a fresh TCP + TLS handshake on every request. Each
5
+ request checks out its own connection, so the transport is safe to use from
6
+ multiple threads (e.g. under ``max_concurrency``). This module is stub-free so
7
+ type checkers read its inline annotations directly.
8
+
9
+ The transport returns a lightweight response object exposing ``status``,
10
+ ``headers`` (a dict), and ``body`` (bytes) — the only fields the client reads.
11
+ """
12
+
13
+ from __future__ import annotations
14
+
15
+ import http.client
16
+ import threading
17
+ from dataclasses import dataclass
18
+ from typing import Any, Mapping
19
+ from urllib.parse import urlsplit
20
+ from urllib.request import Request
21
+
22
+
23
+ def _title_case(name: str) -> str:
24
+ return "-".join(part.capitalize() for part in name.split("-"))
25
+
26
+
27
+ @dataclass(frozen=True)
28
+ class _PooledResponse:
29
+ status: int
30
+ headers: Mapping[str, str]
31
+ body: bytes
32
+
33
+
34
+ class KeepAliveTransport:
35
+ """Connection-pooling transport. Drop-in for the urlopen transport: callable
36
+ as ``transport(request, timeout) -> response``."""
37
+
38
+ def __init__(self, max_per_host: int = 8) -> None:
39
+ self._lock = threading.Lock()
40
+ self._pools: dict[tuple, list[http.client.HTTPConnection]] = {}
41
+ self._max_per_host = max_per_host
42
+
43
+ def __call__(self, request: Request, timeout: float) -> _PooledResponse:
44
+ parts = urlsplit(request.full_url)
45
+ key = (parts.scheme, parts.hostname, parts.port)
46
+ path = parts.path or "/"
47
+ if parts.query:
48
+ path = f"{path}?{parts.query}"
49
+ method = request.get_method()
50
+ # Send canonical HTTP title-case header names (matching the urlopen
51
+ # transport's behavior), so receivers see e.g. "X-Api-Key".
52
+ headers = {_title_case(name): value for name, value in request.header_items()}
53
+ body = request.data
54
+
55
+ last_exc: Exception | None = None
56
+ for attempt in range(2):
57
+ conn = self._checkout(key, parts, timeout)
58
+ try:
59
+ conn.request(method, path, body=body, headers=headers)
60
+ response = conn.getresponse()
61
+ data = response.read()
62
+ result = _PooledResponse(response.status, dict(response.getheaders()), data)
63
+ except (http.client.HTTPException, ConnectionError, OSError) as exc:
64
+ # Likely a stale pooled connection the server already closed;
65
+ # discard it and retry once on a fresh connection.
66
+ last_exc = exc
67
+ self._close(conn)
68
+ if attempt == 1:
69
+ raise
70
+ continue
71
+ if response.will_close:
72
+ self._close(conn)
73
+ else:
74
+ self._checkin(key, conn)
75
+ return result
76
+ raise last_exc if last_exc else RuntimeError("keep-alive transport failed")
77
+
78
+ def close(self) -> None:
79
+ with self._lock:
80
+ pools = list(self._pools.values())
81
+ self._pools.clear()
82
+ for pool in pools:
83
+ for conn in pool:
84
+ self._close(conn)
85
+
86
+ def _checkout(self, key: tuple, parts: Any, timeout: float) -> http.client.HTTPConnection:
87
+ with self._lock:
88
+ pool = self._pools.get(key)
89
+ if pool:
90
+ conn = pool.pop()
91
+ conn.timeout = timeout
92
+ return conn
93
+ return self._new(parts, timeout)
94
+
95
+ def _checkin(self, key: tuple, conn: http.client.HTTPConnection) -> None:
96
+ with self._lock:
97
+ pool = self._pools.setdefault(key, [])
98
+ if len(pool) < self._max_per_host:
99
+ pool.append(conn)
100
+ return
101
+ self._close(conn)
102
+
103
+ @staticmethod
104
+ def _new(parts: Any, timeout: float) -> http.client.HTTPConnection:
105
+ if parts.scheme == "https":
106
+ return http.client.HTTPSConnection(parts.hostname, parts.port or 443, timeout=timeout)
107
+ return http.client.HTTPConnection(parts.hostname, parts.port or 80, timeout=timeout)
108
+
109
+ @staticmethod
110
+ def _close(conn: http.client.HTTPConnection) -> None:
111
+ try:
112
+ conn.close()
113
+ except Exception:
114
+ pass