Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add impersonate_os #78

Merged
merged 2 commits into from
Jan 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 41 additions & 44 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 3 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pyo3 = { version = "0.23.4", features = ["extension-module", "abi3-py38", "index
anyhow = "1.0.95"
tracing = { version = "0.1.41", features = ["log-always"] }
pyo3-log = "0.12.1"
rquest = { version = "1.5.5", features = [
rquest = { version = "2.0.3", features = [
"json",
"cookies",
"socks",
Expand All @@ -26,17 +26,16 @@ rquest = { version = "1.5.5", features = [
"deflate",
"multipart",
"stream",
"impersonate_str",
] }
encoding_rs = { version = "0.8.35" }
foldhash = "0.1.4"
indexmap = { version = "2.7.0", features = ["serde"] }
indexmap = { version = "2.7.1", features = ["serde"] }
tokio = { version = "1.43.0", features = ["full"] }
tokio-util = { version = "0.7.13", features = ["codec"] } # for multipart
html2text = "0.13.6"
bytes = "1.9.0"
pythonize = "0.23.0"
serde_json = "1.0.135"
serde_json = "1.0.137"
webpki-root-certs = "0.26.7"

[profile.release]
Expand Down
20 changes: 18 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ class Client:
OkHttp: "okhttp_3.9","okhttp_3.11","okhttp_3.13","okhttp_3.14","okhttp_4.9","okhttp_4.10","okhttp_5"
Edge: "edge_101","edge_122","edge_127","edge_131"
Firefox: "firefox_109","firefox_117","firefox_128","firefox_133"
impersonate_os (str | None): impersonate OS. Example: "windows". Default is "linux".
Android: "android", iOS: "ios", Linux: "linux", Mac OS: "macos", Windows: "windows"
follow_redirects (bool | None): Whether to follow redirects. Default is True.
max_redirects (int | None): Maximum redirects to follow. Default 20. Applies if `follow_redirects` is True.
verify (bool | None): Verify SSL certificates. Default is True.
Expand Down Expand Up @@ -147,6 +149,8 @@ resp.url

#### Devices

##### Impersonate

- Chrome: `chrome_100`,`chrome_101`,`chrome_104`,`chrome_105`,`chrome_106`,`chrome_107`,`chrome_108`,`chrome_109`,`chrome_114`,`chrome_116`,`chrome_117`,`chrome_118`,`chrome_119`,`chrome_120`,`chrome_123`,`chrome_124`,`chrome_126`,`chrome_127`,`chrome_128`,`chrome_129`,`chrome_130`,`chrome_131`

- Edge: `edge_101`,`edge_122`,`edge_127`, `edge_131`
Expand All @@ -157,13 +161,25 @@ resp.url

- Firefox: `firefox_109`, `firefox_117`, `firefox_128`, `firefox_133`

##### Impersonate OS

- Android: `android`

- iOS: `ios`

- Linux: `linux`

- Mac OS: `macos`

- Windows: `windows`

#### Examples

```python
import primp

# Impersonate
client = primp.Client(impersonate="chrome_131") # chrome_131
client = primp.Client(impersonate="chrome_131", impersonate_os="windows") # chrome_131 + windows

# GET request
resp = client.get("https://tls.peet.ws/api/all")
Expand Down Expand Up @@ -224,7 +240,7 @@ print(resp.json())
# You can also use convenience functions that use a default Client instance under the hood:
# primp.get() | primp.head() | primp.options() | primp.delete() | primp.post() | primp.patch() | primp.put()
# These functions can accept the `impersonate` parameter:
resp = primp.get("https://httpbin.org/anything", impersonate="chrome_131")
resp = primp.get("https://httpbin.org/anything", impersonate="chrome_131", impersonate_os="android")
print(r.text)
```

Expand Down
9 changes: 9 additions & 0 deletions primp.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,14 @@ IMPERSONATE = Literal[
"firefox_133",
]

IMPERSONATE_OS = Literal[
"android",
"ios",
"linux",
"macos",
"windows",
]

class Response:
@property
def content(self) -> bytes: ...
Expand Down Expand Up @@ -94,6 +102,7 @@ class Client:
referer: bool | None = True,
proxy: str | None = None,
impersonate: IMPERSONATE | None = None,
impersonate_os: IMPERSONATE_OS | None = None,
follow_redirects: bool | None = True,
max_redirects: int | None = 20,
verify: bool | None = True,
Expand Down
Loading
Loading