PyCurl is a Python package that provides a simple and flexible interface for making HTTP requests. It's designed to handle customizable configurations and error management, enabling easy execution of GET, POST, PUT, and DELETE requests.
- Defines a base URL for all requests.
- Configures headers, cookies, and basic or token authentication.
- Handles redirects and timeouts.
- Manages and saves cookies to files.
- Extracts and manages HTTP response errors.
- Resets the HTTP client configuration to its initial state.
You can install PyCurl using pip:
pip install PyCurlify
from Curl import PyCurlify
# Create an instance of PyCurl
http_client = PyCurl()
# Set the base URL
http_client.base_url = "https://api.example.com"
# Set headers
http_client.set_header('Authorization', 'Bearer my_token')
# Make a GET request
response = http_client.get("https://api.example.com/v1/endpoint")
print(response)
__init__(self)
Initializes a new instance of the PyCurl
class.
set_timeout(self, timeout)
Sets the timeout for requests.
set_referer(self, referer)
Sets the Referer header for requests.
set_header(self, key, value)
Sets a custom header for requests.
set_basic_auth(self, username, password)
Sets basic authentication for requests.
set_bearer_auth(self, token)
Sets Bearer token authentication for requests.
set_user_agent(self, user_agent)
Sets the User-Agent for requests.
set_follow_redirects(self, follow=True)
Sets whether to follow redirects.
set_cookie(self, name, value)
Sets a cookie for requests.
get(self, url, params=None)
Makes a GET request.
url
(str): The URL to make the request to.params
(dict): Query parameters. Defaults to None.
- The response of the request.
post(self, url, data=None)
Makes a POST request.
url
(str): The URL to make the request to.data
(dict): Data to send in the request. Defaults to None.
- The response of the request.
put(self, url, data=None)
Makes a PUT request.
url
(str): The URL to make the request to.data
(dict): Data to send in the request. Defaults to None.
- The response of the request.
delete(self, url)
Makes a DELETE request.
url
(str): The URL to make the request to.
- The response of the request.
upload_ftp(self, host, username, password, file_path, upload_dir, port=21, passive=True)
Uploads a file to an FTP server and displays progress.
host
(str): The host of the FTP server.username
(str): The username for authentication.password
(str): The password for authentication.file_path
(str): The path of the file to upload.upload_dir
(str): The destination directory on the FTP server.port
(int): The port to connect to on the FTP server. Defaults to 21.passive
(bool): Whether to use passive mode. Defaults to True.
- str: The full path where the file was uploaded on the FTP server.
download_large_file(self, url, method='get', params=None, chunk_size=8192, download_dir=None, file_name=None)
Downloads a large file and displays progress.
url
(str): The URL of the file.method
(str): The HTTP method (GET or POST). Defaults to 'get'.params
(dict): Request parameters. Defaults to None.chunk_size
(int): Chunk size for download. Defaults to 8192 bytes.download_dir
(str): Directory to save the file. Defaults to None.
- The path to the downloaded file if the download was successful, None otherwise.
reset(self)
Resets the HTTP client to its initial state.
- None
get_error_message(self)
Gets the error message from the last failed request.
- The error message.
get_error_code(self)
Gets the error code from the last failed request.
- The error code.
- requests
- tqdm
You can install these libraries using pip:
pip install requests tqdm
These libraries are required to run the code provided in this documentation.
Contributions are welcome! If you'd like to contribute to PyCurl, you can follow these steps:
- Fork the repository from here.
- Clone your fork:
git clone https://github.com/YOUR_USERNAME/PyCurl.git
- Create a branch for your contribution:
git checkout -b my-contribution
- Make your changes and commit:
git commit -am 'Add my contribution'
- Push your changes to your fork:
git push origin my-contribution
- Open a pull request in the original repository.
Thank you for contributing!
This project is licensed under the Open Software License ("OSL") v 3.0. You can find the full text of the license here.