---
title: Using Requests and HTTPX
sidebar_label: Using Requests and HTTPX
---

In this guide, you'll learn how to use the [Requests](https://requests.readthedocs.io) and [HTTPX](https://www.python-httpx.org/) libraries for making HTTP requests in your Apify Actors.

## Introduction

To use either of the libraries mentioned below in your Actors,
you can start from the [Start with Python](https://apify.com/templates?category=python) Actor template.

## Requests

The [`requests`](https://requests.readthedocs.io) library is one of the most popular Python libraries for making HTTP requests.

To use it in your Actors, no special configuration is needed.
Just put `requests` in your `requirements.txt` file,
[reinstall dependencies](../introduction/quick-start#adding-dependencies) if you're running the Actor locally,
and you're good to go.

```python title="src/main.py"
import requests
from apify import Actor

async def main():
    async with Actor:
        response = requests.get('http://example.com')
        print(response.text)
```

### Using proxies with requests

To use Apify Proxy with `requests`,
you can just generate a proxy URL through [`Actor.create_proxy_configuration()`](../../reference/class/Actor#create_proxy_configuration),
and pass it to `requests` using the [`proxies` argument](https://requests.readthedocs.io/en/latest/user/advanced/#proxies):

```python title="src/main.py"
import requests
from apify import Actor

async def main():
    async with Actor:
        proxy_configuration = await Actor.create_proxy_configuration()
        proxy_url = await proxy_configuration.new_url()
        proxies = {
            'http': proxy_url,
            'https': proxy_url,
        }

        response = requests.get('http://example.com', proxies=proxies)
        print(response.text)
```

To learn more about using proxies in your Actor with `requests`, check the [documentation for proxy management](../concepts/proxy-management).

## HTTPX

Another very popular Python library for performing HTTP requests is [`HTTPX`](https://www.python-httpx.org/).
Its main advantage over `requests` is the ability to [perform asynchronous HTTP requests](https://www.python-httpx.org/async/),
making it ideal for large-scale, parallel web scraping.

To use it in your Actors, no special configuration is needed.
Just put `httpx` in your `requirements.txt` file,
[reinstall dependencies](../introduction/quick-start#adding-dependencies) if you're running the Actor locally,
and you're good to go.

```python title="src/main.py"
import asyncio
import httpx
from apify import Actor

async def main():
    async with Actor:
        async with httpx.AsyncClient() as httpx_client:
            # This will perform all the requests in parallel
            http_requests = []
            for i in range(10):
                http_requests.append(httpx_client.get(f'http://example.com/{i}'))

            responses = await asyncio.gather(*http_requests)
            print(responses)
```

### Using proxies with HTTPX

To use Apify Proxy with `httpx`,
you can just generate a proxy URL through [`Actor.create_proxy_configuration()`](../../reference/class/Actor#create_proxy_configuration),
and pass it to `httpx` using the [`proxies` argument](https://requests.readthedocs.io/en/latest/user/advanced/#proxies):

```python title="src/main.py"
import httpx
from apify import Actor

async def main():
    async with Actor:
        proxy_configuration = await Actor.create_proxy_configuration()
        proxy_url = await proxy_configuration.new_url()
        async with httpx.AsyncClient(proxies=proxy_url) as httpx_client:
            response = httpx_client.get(f'http://example.com'),
            print(response)
```

To learn more about using proxies in your Actor with `httpx`, check the [documentation for proxy management](../concepts/proxy-management).

## Conclusion

In this guide, you learned how to use the Requests and HTTPX libraries for making HTTP requests in your Apify Actors. These libraries provide flexible and efficient ways to fetch web content, with HTTPX offering asynchronous support for parallel requests. If you have questions or need assistance, feel free to reach out on our [GitHub](https://github.com/apify/apify-sdk-python) or join our [Discord community](https://discord.com/invite/jyEM2PRvMU). Happy scraping!

## Additional resources

- [Apify templates: Getting started with Python](https://apify.com/templates/python-start)
- [Requests: Official documentation](https://requests.readthedocs.io)
- [HTTPX: Official documentation](https://www.python-httpx.org/)
