|
| 1 | +# Hyper Solutions SDK for Python |
| 2 | + |
| 3 | +## Installation |
| 4 | + |
| 5 | +To use the Hyper Solutions SDK in your Python project, you need to install it using the following command: |
| 6 | + |
| 7 | +``` |
| 8 | +pip install hyper-sdk |
| 9 | +``` |
| 10 | + |
| 11 | +## Usage |
| 12 | + |
| 13 | +### Creating a Session |
| 14 | + |
| 15 | +To start using the SDK, you need to create a new `Session` instance by providing your API key: |
| 16 | + |
| 17 | +```python |
| 18 | +from hyper_sdk import Session |
| 19 | + |
| 20 | +session = Session(api_key="your-api-key") |
| 21 | +``` |
| 22 | + |
| 23 | +You can also optionally set a JWT key and a custom HTTP client: |
| 24 | + |
| 25 | +```python |
| 26 | +from hyper_sdk import Session |
| 27 | + |
| 28 | +session = Session(api_key="your-api-key", jwt_key="your-jwt-key", client=custom_http_client) |
| 29 | +``` |
| 30 | + |
| 31 | +## Akamai |
| 32 | + |
| 33 | +The Akamai package provides functions for interacting with Akamai Bot Manager, including generating sensor data, parsing script path, parsing pixel challenges, and handling sec-cpt challenges. |
| 34 | + |
| 35 | +### Generating Sensor Data |
| 36 | + |
| 37 | +To generate sensor data required for generating valid Akamai cookies, use the `generate_sensor_data` method: |
| 38 | + |
| 39 | +```python |
| 40 | +from hyper_sdk import SensorInput |
| 41 | + |
| 42 | +sensor_input = SensorInput( |
| 43 | + page_url="https://example.com/", |
| 44 | + user_agent="your-user-agent", |
| 45 | + abck="your-abck-cookie", |
| 46 | + bmsz="your-bmsz-cookie", |
| 47 | + version="2.0" |
| 48 | +) |
| 49 | +sensor_data = session.generate_sensor_data(sensor_input) |
| 50 | +``` |
| 51 | + |
| 52 | +### Parsing Script Path |
| 53 | + |
| 54 | +To parse the Akamai Bot Manager script path from the given HTML code, use the `parse_script_path` function from the `script_path` module: |
| 55 | + |
| 56 | +```python |
| 57 | +from hyper_sdk.akamai.script_path import parse_script_path |
| 58 | + |
| 59 | +script_path = parse_script_path(html_source) |
| 60 | +``` |
| 61 | + |
| 62 | +### Handling Sec-Cpt Challenges |
| 63 | + |
| 64 | +The Akamai package provides functions for handling sec-cpt challenges: |
| 65 | + |
| 66 | +- `SecCptChallenge.parse`: Parses a sec-cpt challenge from an HTML source. |
| 67 | +- `generate_sec_cpt_payload`: Generates a sec-cpt payload using the provided sec-cpt cookie. |
| 68 | +- `sleep`: Sleeps for the duration specified in the sec-cpt challenge. |
| 69 | + |
| 70 | +Example usage: |
| 71 | + |
| 72 | +```python |
| 73 | +from hyper_sdk.akamai.sec_cpt import SecCptChallenge |
| 74 | + |
| 75 | +challenge = SecCptChallenge.parse(html_source) |
| 76 | +payload = challenge.generate_sec_cpt_payload(sec_cpt_cookie) |
| 77 | +challenge.sleep() |
| 78 | +``` |
| 79 | + |
| 80 | +### Validating Cookies |
| 81 | + |
| 82 | +The Akamai package provides functions for validating cookies: |
| 83 | + |
| 84 | +- `is_cookie_valid`: Determines if the provided `_abck` cookie value is valid based on the given request count. |
| 85 | +- `is_cookie_invalidated`: Determines if the current session requires more sensors to be sent. |
| 86 | + |
| 87 | +Example usage: |
| 88 | + |
| 89 | +```python |
| 90 | +from hyper_sdk.akamai.stop_signal import is_cookie_valid, is_cookie_invalidated |
| 91 | + |
| 92 | +is_valid = is_cookie_valid(abck_cookie, request_count) |
| 93 | +is_invalidated = is_cookie_invalidated(abck_cookie) |
| 94 | +``` |
| 95 | + |
| 96 | +### Generating Pixel Data |
| 97 | + |
| 98 | +To generate pixel data, use the `generate_pixel_data` method: |
| 99 | + |
| 100 | +```python |
| 101 | +from hyper_sdk import PixelInput |
| 102 | + |
| 103 | +pixel_input = PixelInput( |
| 104 | + user_agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.82 Safari/537.36", |
| 105 | + html_var="your-html-var", |
| 106 | + script_var="your-script-var" |
| 107 | +) |
| 108 | +pixel_data = session.generate_pixel_data(pixel_input) |
| 109 | +``` |
| 110 | + |
| 111 | +### Parsing Pixel Challenges |
| 112 | + |
| 113 | +The Akamai package provides functions for parsing pixel challenges: |
| 114 | + |
| 115 | +- `parse_pixel_html_var`: Parses the required pixel challenge variable from the given HTML code. |
| 116 | +- `parse_pixel_script_url`: Parses the script URL of the pixel challenge script and the URL to post a generated payload to from the given HTML code. |
| 117 | +- `parse_pixel_script_var`: Parses the dynamic value from the pixel script. |
| 118 | + |
| 119 | +Example usage: |
| 120 | + |
| 121 | +```python |
| 122 | +from hyper_sdk.akamai.pixel import parse_pixel_html_var, parse_pixel_script_url, parse_pixel_script_var |
| 123 | + |
| 124 | +html_var = parse_pixel_html_var(html_source) |
| 125 | +script_url, post_url = parse_pixel_script_url(html_source) |
| 126 | +script_var = parse_pixel_script_var(script_source) |
| 127 | +``` |
| 128 | + |
| 129 | + |
| 130 | +## Incapsula |
| 131 | + |
| 132 | +The Incapsula package provides functions for interacting with Imperva Incapsula, including generating Reese84 sensor data, UTMVC cookies, and parsing UTMVC script paths. |
| 133 | + |
| 134 | +### Generating Reese84 Sensor |
| 135 | + |
| 136 | +To generate sensor data required for generating valid Reese84 cookies, use the `generate_reese84_sensor` method: |
| 137 | + |
| 138 | +```python |
| 139 | +sensor_data = session.generate_reese84_sensor(site="example.com", user_agent="your-user-agent") |
| 140 | +``` |
| 141 | + |
| 142 | +### Generating UTMVC Cookie |
| 143 | + |
| 144 | +To generate the UTMVC cookie using the Hyper Solutions API, use the `generate_utmvc_cookie` method: |
| 145 | + |
| 146 | +```python |
| 147 | +from hyper_sdk import UtmvcInput |
| 148 | + |
| 149 | +utmvc_input = UtmvcInput( |
| 150 | + user_agent="your-user-agent", |
| 151 | + session_ids=["session-id-1", "session-id-2"], |
| 152 | + script="your-script" |
| 153 | +) |
| 154 | +utmvc_cookie = session.generate_utmvc_cookie(utmvc_input) |
| 155 | +``` |
| 156 | + |
| 157 | +### Parsing UTMVC Script Path |
| 158 | + |
| 159 | +To parse the UTMVC script path from a given script content, use the `parse_utmvc_script_path` function from the `utmvc` module: |
| 160 | + |
| 161 | +```python |
| 162 | +from hyper_sdk.incapsula.utmvc import parse_utmvc_script_path |
| 163 | + |
| 164 | +script_path = parse_utmvc_script_path(script_content) |
| 165 | +``` |
| 166 | + |
| 167 | +### Generating UTMVC Submit Path |
| 168 | + |
| 169 | +To generate a unique UTMVC submit path with a random query parameter, use the `get_utmvc_submit_path` function from the `utmvc` module: |
| 170 | + |
| 171 | +```python |
| 172 | +from hyper_sdk.incapsula.utmvc import get_utmvc_submit_path |
| 173 | + |
| 174 | +submit_path = get_utmvc_submit_path() |
| 175 | +``` |
0 commit comments