Skip to content

Commit b879d2d

Browse files
VinciGit00claude
andcommitted
fix: define the User-Agent as a single module variable
Drops the env.py indirection and the python-version suffix: one USER_AGENT constant in client.py, reused by async_client.py. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent a60997a commit b879d2d

4 files changed

Lines changed: 6 additions & 12 deletions

File tree

src/scrapegraph_py/async_client.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
import httpx
1212
from pydantic import BaseModel, TypeAdapter
1313

14-
from .env import USER_AGENT, env
14+
from .client import USER_AGENT
15+
from .env import env
1516
from .schemas import (
1617
ApiResult,
1718
CrawlPagesQuery,

src/scrapegraph_py/client.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@
66
import sys
77
import time
88
from datetime import datetime
9+
from importlib import metadata
910
from typing import Literal
1011

1112
import httpx
1213
from pydantic import BaseModel, TypeAdapter
1314

14-
from .env import USER_AGENT, env
15+
from .env import env
1516
from .schemas import (
1617
ApiResult,
1718
CrawlPagesQuery,
@@ -44,6 +45,7 @@
4445
)
4546

4647
_SERVER_TIMING_RE = re.compile(r"dur=(\d+(?:\.\d+)?)")
48+
USER_AGENT = f"scrapegraph-py/{metadata.version('scrapegraph-py')}"
4749

4850

4951
def _debug(label: str, data: object = None) -> None:

src/scrapegraph_py/env.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,6 @@
11
from __future__ import annotations
22

33
import os
4-
import platform
5-
from importlib.metadata import PackageNotFoundError, version
6-
7-
try:
8-
__version__ = version("scrapegraph-py")
9-
except PackageNotFoundError: # local checkout without an installed distribution
10-
__version__ = "unknown"
11-
12-
USER_AGENT = f"scrapegraph-py/{__version__} python/{platform.python_version()}"
134

145

156
class Env:

tests/test_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
ScrapeGraphAI,
1616
ScreenshotFormatConfig,
1717
)
18-
from scrapegraph_py.env import USER_AGENT
18+
from scrapegraph_py.client import USER_AGENT
1919

2020
API_KEY = "test-sgai-key"
2121
BASE_URL = "https://api.scrapegraphai.com/v2"

0 commit comments

Comments
 (0)