Metadata-Version: 2.4
Name: feasibility
Version: 0.0.3
Summary: Feasibility checker
Author: Ayush Thakkar
License: MIT
Requires-Python: >=3.8
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: curl2python
Requires-Dist: openpyxl
Dynamic: license-file

# curl-feasibility

A cURL-based feasibility testing framework for APIs and web scraping.

The library converts cURL commands into executable Python request configurations and provides a simple `FeasibilityChecker` class for testing request feasibility, concurrent execution, response validation, and result reporting.

## Features

- Convert cURL commands into Python request configuration using `curl2python`
- Support for:
  - Headers
  - Cookies
  - Query parameters
  - JSON payloads
  - Form data
- Optional custom headers and cookies
  - If provided, custom headers/cookies override the values generated from cURL
  - If not provided, values from the cURL command are used
- Multiple request engines:
  - `requests`
  - `curl_cffi`
- Browser impersonation support with `curl_cffi`
- Concurrent request execution
- Configurable batches and threads
- Retry support
- Response text validation
- Excel summary export

---

# Installation

## Basic Installation

```bash
pip install feasibility
```



---

# Basic Usage

Import `FeasibilityChecker` and provide the cURL command:

```python
from feasibility import FeasibilityChecker

curl = """
curl 'https://example.com/api/products' \
  -H 'User-Agent: Mozilla/5.0'
"""

checker = FeasibilityChecker(curl)

checker.run(
    text_to_find="Product",
    total_batches=10,
    requests_per_batch=10,
    num_threads=10
)
```

The cURL command is automatically converted into a Python request configuration using `curl2python`.

---

# Using Custom Headers and Cookies

Headers and cookies can optionally be provided separately.

When custom headers or cookies are provided, they are used instead of the corresponding values generated from the cURL command.

```python
from feasibility import FeasibilityChecker

curl = """
curl 'https://example.com/api/products'
"""

headers = {
    "User-Agent": "Mozilla/5.0",
    "Accept": "application/json",
    "Authorization": "Bearer YOUR_TOKEN"
}

cookies = {
    "session_id": "YOUR_SESSION_ID"
}

checker = FeasibilityChecker(
    curl_text=curl,
    headers=headers,
    cookies=cookies
)

checker.run(
    text_to_find="Product",
    total_batches=5,
    requests_per_batch=20,
    num_threads=10
)
```

You can provide only headers or only cookies as well.

### Headers only

```python
checker = FeasibilityChecker(
    curl_text=curl,
    headers={
        "User-Agent": "Mozilla/5.0"
    }
)
```

### Cookies only

```python
checker = FeasibilityChecker(
    curl_text=curl,
    cookies={
        "session_id": "abc123"
    }
)
```

---

# Using Requests

`requests` is the default request engine.

```python
from feasibility import FeasibilityChecker

checker = FeasibilityChecker(
    curl_text=curl,
    engine="requests"
)

checker.run(
    text_to_find="success"
)
```

---

# Using curl_cffi

For websites that require browser-like TLS/client impersonation, you can use `curl_cffi`.

First install it:



Then:

```python
from feasibility import FeasibilityChecker

checker = FeasibilityChecker(
    curl_text=curl,
    engine="curl_cffi",
    impersonate="chrome"
)

checker.run(
    text_to_find="Product"
)
```

The `impersonate` value is passed to `curl_cffi` when using the `curl_cffi` engine.

---

# Concurrent Requests

The checker supports configurable batches, requests per batch, and threads.

```python
checker.run(
    text_to_find="Product",
    total_batches=10,
    requests_per_batch=100,
    num_threads=20
)
```

This configuration performs:

```text
10 batches
100 requests per batch
20 concurrent worker threads
```

for a total of:

```text
1000 requests
```

---

# Retries

Requests can automatically be retried when an exception occurs.

```python
checker.run(
    text_to_find="Product",
    total_batches=5,
    requests_per_batch=20,
    num_threads=10,
    max_retries=3
)
```

The default value of `max_retries` is `3`.

---

# Response Validation

Use `text_to_find` to check whether specific text exists in the response.

```python
checker.run(
    text_to_find="Product"
)
```

For each request, the checker records:

- Request ID
- HTTP status code
- Whether the expected text was found
- Request time
- Number of attempts

Example console output:

```text
=== Batch 1/10 ===

[DONE] Req 1 | Status: 200 | Found: True
[DONE] Req 2 | Status: 200 | Found: True
[DONE] Req 3 | Status: 403 | Found: False
```

---

# Excel Output

Results are automatically exported to an Excel file.

```python
checker.run(
    text_to_find="Product",
    excel_file="summary.xlsx"
)
```

The generated Excel file contains:

| Request ID | Status Code | Text Found | Request Time | Attempts |
|------------|-------------|------------|--------------|----------|
| 1 | 200 | YES | 0.82 | 1 |
| 2 | 200 | YES | 0.91 | 1 |
| 3 | 403 | NO | 0.45 | 1 |

---

# Complete Example

```python
from feasibility import FeasibilityChecker

curl = """
curl 'https://example.com/api/products?page=1' \
  -H 'Accept: application/json'
"""

headers = {
    "User-Agent": "Mozilla/5.0",
    "Accept": "application/json"
}

cookies = {
    "session_id": "abc123"
}

checker = FeasibilityChecker(
    curl_text=curl,
    engine="requests",
    headers=headers,
    cookies=cookies
)

checker.run(
    text_to_find="Product",
    total_batches=10,
    requests_per_batch=100,
    num_threads=20,
    sleep_between_batches=1,
    max_retries=3,
    excel_file="summary.xlsx"
)
```

---

# Configuration

`FeasibilityChecker` supports the following parameters:

| Parameter | Default | Description |
|-----------|---------|-------------|
| `curl_text` | Required | cURL command used to generate the request |
| `engine` | `requests` | Request engine: `requests` or `curl_cffi` |
| `impersonate` | `None` | Browser impersonation value for `curl_cffi` |
| `headers` | `None` | Optional custom headers |
| `cookies` | `None` | Optional custom cookies |

The `.run()` method supports:

| Parameter | Default | Description |
|-----------|---------|-------------|
| `text_to_find` | Required | Text to search for in the response |
| `total_batches` | `10` | Number of batches |
| `requests_per_batch` | `10` | Requests in each batch |
| `num_threads` | `10` | Number of concurrent workers |
| `sleep_between_batches` | `1` | Delay between batches in seconds |
| `max_retries` | `3` | Maximum retry attempts |
| `excel_file` | `summary.xlsx` | Output Excel filename |

---

# How It Works

```text
cURL Command
     │
     ▼
curl2python
     │
     ▼
Python Request Configuration
     │
     ├── Custom Headers (optional)
     ├── Custom Cookies (optional)
     │
     ▼
RequestEngine
     │
     ├── requests
     │
     └── curl_cffi
             │
             └── Browser Impersonation
     │
     ▼
Concurrent Requests
     │
     ▼
Response Validation
     │
     ▼
Excel Summary
```

---

# Use Cases

This package can be used for:

- API feasibility testing
- Web scraping feasibility checks
- Proxy/request testing
- Header and cookie testing
- Anti-bot/browser impersonation testing
- Concurrent request testing
- Response validation
- Request performance testing

---

# License

MIT License
