METADATA 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. Metadata-Version: 2.4
  2. Name: primp
  3. Version: 1.1.3
  4. Classifier: Programming Language :: Rust
  5. Classifier: Programming Language :: Python :: 3
  6. Classifier: Programming Language :: Python :: 3 :: Only
  7. Classifier: Programming Language :: Python :: 3.10
  8. Classifier: Programming Language :: Python :: 3.11
  9. Classifier: Programming Language :: Python :: 3.12
  10. Classifier: Programming Language :: Python :: 3.13
  11. Classifier: Programming Language :: Python :: 3.14
  12. Classifier: Programming Language :: Python :: Implementation :: CPython
  13. Classifier: Programming Language :: Python :: Implementation :: PyPy
  14. Classifier: Topic :: Internet :: WWW/HTTP
  15. Classifier: Topic :: Software Development :: Libraries :: Python Modules
  16. Requires-Dist: certifi ; extra == 'dev'
  17. Requires-Dist: pytest>=8.1.1 ; extra == 'dev'
  18. Requires-Dist: pytest-asyncio>=0.25.3 ; extra == 'dev'
  19. Requires-Dist: typing-extensions ; python_full_version < '3.12' and extra == 'dev'
  20. Requires-Dist: mypy>=1.14.1 ; extra == 'dev'
  21. Requires-Dist: ruff>=0.9.2 ; extra == 'dev'
  22. Provides-Extra: dev
  23. Summary: HTTP client that can impersonate web browsers
  24. Keywords: python,request,impersonate
  25. Author: deedy5
  26. License: MIT License
  27. Requires-Python: >=3.10
  28. Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
  29. Project-URL: repository, https://github.com/deedy5/primp
  30. ![Python >= 3.10](https://img.shields.io/badge/python->=3.10-red.svg) [![](https://badgen.net/github/release/deedy5/primp)](https://github.com/deedy5/primp/releases) [![](https://badge.fury.io/py/primp.svg)](https://pypi.org/project/primp) [![Downloads](https://static.pepy.tech/badge/primp/week)](https://pepy.tech/project/primp) [![CI](https://github.com/deedy5/primp/actions/workflows/CI.yml/badge.svg?branch=main)](https://github.com/deedy5/primp/actions/workflows/CI.yml)
  31. # 🪞 PRIMP 🐍
  32. > HTTP client that can impersonate web browsers.
  33. ## 📦 Installation
  34. ```bash
  35. pip install -U primp
  36. ```
  37. ## 🔧 Building from Source
  38. ```bash
  39. git clone https://github.com/deedy5/primp.git && cd primp
  40. # Build python library using cargo
  41. cargo build -r -p primp-python
  42. # Build python library using maturin
  43. cd crates/primp-python
  44. python -m venv .venv && source .venv/bin/activate # Linux/macOS
  45. pip install maturin && maturin develop -r
  46. ```
  47. ## 🚀 Quick Start
  48. ### Sync API
  49. ```python
  50. import primp
  51. # Create client with browser impersonation
  52. client = primp.Client(impersonate="chrome_145")
  53. # Make requests
  54. resp = client.get("https://tls.peet.ws/api/all")
  55. print(resp.status_code) # 200
  56. print(resp.text) # Response body
  57. print(resp.json()) # Parsed JSON
  58. ```
  59. ### Async API
  60. ```python
  61. import asyncio
  62. import primp
  63. async def main():
  64. async with primp.AsyncClient(impersonate="chrome_145") as client:
  65. resp = await client.get("https://tls.peet.ws/api/all")
  66. print(resp.text)
  67. asyncio.run(main())
  68. ```
  69. ## 📊 Benchmark
  70. ![](./benchmark/benchmark.jpg)
  71. ## 🎭 Browser Impersonation
  72. <table>
  73. <tr>
  74. <td valign="top">
  75. | Browser | Profiles |
  76. |:--------|:---------|
  77. | 🌐 **Chrome** | `chrome_144`, `chrome_145` |
  78. | 🧭 **Safari** | `safari_18.5`, `safari_26` |
  79. | 🔷 **Edge** | `edge_144`, `edge_145` |
  80. | 🦊 **Firefox** | `firefox_140`, `firefox_146` |
  81. | ⭕ **Opera** | `opera_126`, `opera_127` |
  82. | 🎲 **Random** | `random` |
  83. </td>
  84. <td valign="top">
  85. | OS | Value |
  86. |:---|:------|
  87. | 🤖 Android | `android` |
  88. | 🍎 iOS | `ios` |
  89. | 🐧 Linux | `linux` |
  90. | 🍏 macOS | `macos` |
  91. | 🪟 Windows | `windows` |
  92. | 🎲 Random | `random` |
  93. </td>
  94. </tr>
  95. </table>
  96. ## ⚡ Features
  97. - 🔥 **Fast** - Built with Rust
  98. - 🎭 **Browser Impersonation** - Mimic Chrome, Safari, Firefox, Edge, Opera
  99. - 🌍 **OS Impersonation** - Windows, Linux, macOS, Android, iOS
  100. - 🔄 **Sync & Async** - Both APIs available
  101. - 🍪 **Cookie Management** - Persistent cookie store
  102. - 🌐 **Proxy Support** - HTTP, HTTPS, SOCKS5
  103. - 📝 **HTML Conversion** - Convert to markdown, plain text, rich text
  104. - 📤 **File Uploads** - Multipart/form-data support
  105. - 🔐 **SSL Verification** - Custom CA certificates
  106. ## 📖 Response Object
  107. ### Standard Response
  108. All properties work identically for both sync and async responses:
  109. | Property | Type | Description |
  110. |:---------|:-----|:------------|
  111. | `.url` | `str` | Final response URL (after redirects) |
  112. | `.status_code` | `int` | HTTP status code |
  113. | `.content` | `bytes` | Raw response body as bytes |
  114. | `.encoding` | `str` | Character encoding (read/write) |
  115. | `.text` | `str` | Decoded text content |
  116. | `.headers` | `dict` | Response headers dictionary |
  117. | `.cookies` | `dict` | Response cookies |
  118. | `.text_markdown` | `str` | HTML converted to Markdown |
  119. | `.text_plain` | `str` | HTML converted to plain text |
  120. | `.text_rich` | `str` | HTML converted to rich text |
  121. | Method | Description |
  122. |:-------|:------------|
  123. | `.json()` | Parse response body as JSON. Raises `json.JSONDecodeError` on invalid JSON. |
  124. | `.raise_for_status()` | Raise `StatusError` for 4xx/5xx status codes |
  125. ### Streaming Response
  126. Use `stream=True` to get a `StreamResponse` for efficient handling of large data:
  127. ```python
  128. # Sync streaming
  129. with primp.get("https://example.com/large-file.zip", stream=True) as response:
  130. for chunk in response.iter_bytes():
  131. process(chunk)
  132. # Async streaming
  133. async with await client.get("https://example.com/large-file.zip", stream=True) as response:
  134. async for chunk in response.aiter_bytes():
  135. process(chunk)
  136. ```
  137. | Sync Method | Async Method | Description |
  138. |:------------|:-------------|:------------|
  139. | `.read()` | `.aread()` | Read remaining content into memory |
  140. | `.iter_bytes(chunk_size)` | `.aiter_bytes(chunk_size)` | Iterate over byte chunks |
  141. | `.iter_text(chunk_size)` | `.aiter_text(chunk_size)` | Iterate over decoded text chunks |
  142. | `.iter_lines()` | `.aiter_lines()` | Iterate over lines |
  143. | `.next()` | `.anext()` | Get next chunk explicitly |
  144. | `.close()` | `.aclose()` | Close response and release resources |
  145. ## 📚 Examples
  146. See the [`/examples`](examples/) folder for detailed usage:
  147. - [`basic_usage.py`](examples/basic_usage.py) - GET, POST, params, headers
  148. - [`async_usage.py`](examples/async_usage.py) - Async client, concurrent requests
  149. - [`authentication.py`](examples/authentication.py) - Basic auth, bearer tokens
  150. - [`proxy.py`](examples/proxy.py) - HTTP/SOCKS5 proxies
  151. - [`cookies.py`](examples/cookies.py) - Cookie management
  152. - [`streaming.py`](examples/streaming.py) - Response streaming
  153. - [`post_requests.py`](examples/post_requests.py) - POST/PUT/PATCH/DELETE
  154. - [`error_handling.py`](examples/error_handling.py) - Exception handling
  155. - [`html_conversion.py`](examples/html_conversion.py) - HTML to text
  156. ___
  157. ## Disclaimer
  158. This tool is for educational purposes only. Use it at your own risk.