Skip to main content

PyCurl: Un envoltorio flexible alrededor de la biblioteca requests para realizar solicitudes HTTP.

Project description

PyCurlify

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.

Key Features:

  • 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.

Installation

You can install PyCurl using pip:

pip install PyCurlify

Usage

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)

Class PyCurl

Methods

__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.

Parameters:
  • url (str): The URL to make the request to.
  • params (dict): Query parameters. Defaults to None.
Returns:
  • The response of the request.
post(self, url, data=None)

Makes a POST request.

Parameters:
  • url (str): The URL to make the request to.
  • data (dict): Data to send in the request. Defaults to None.
Returns:
  • The response of the request.
put(self, url, data=None)

Makes a PUT request.

Parameters:
  • url (str): The URL to make the request to.
  • data (dict): Data to send in the request. Defaults to None.
Returns:
  • The response of the request.
delete(self, url)

Makes a DELETE request.

Parameters:
  • url (str): The URL to make the request to.
Returns:
  • 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.

Parameters:
  • 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.
Returns:
  • 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.

Parameters:
  • 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.
Returns:
  • The path to the downloaded file if the download was successful, None otherwise.
reset(self)

Resets the HTTP client to its initial state.

Returns:
  • None
get_error_message(self)

Gets the error message from the last failed request.

Returns:
  • The error message.
get_error_code(self)

Gets the error code from the last failed request.

Returns:
  • The error code.

Requirements

  • 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

Contributions are welcome! If you'd like to contribute to PyCurl, you can follow these steps:

  1. Fork the repository from here.
  2. Clone your fork: git clone https://github.com/YOUR_USERNAME/PyCurl.git
  3. Create a branch for your contribution: git checkout -b my-contribution
  4. Make your changes and commit: git commit -am 'Add my contribution'
  5. Push your changes to your fork: git push origin my-contribution
  6. Open a pull request in the original repository.

Thank you for contributing!

License

This project is licensed under the Open Software License ("OSL") v 3.0. You can find the full text of the license here.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

PyCurlify-2.0.0.tar.gz (11.1 kB view details)

Uploaded Source

File details

Details for the file PyCurlify-2.0.0.tar.gz.

File metadata

  • Download URL: PyCurlify-2.0.0.tar.gz
  • Upload date:
  • Size: 11.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.10.6

File hashes

Hashes for PyCurlify-2.0.0.tar.gz
Algorithm Hash digest
SHA256 fb7674d48ce00b3c2b06d94106accb279a8c29aeaa6679cbc1de0650463b2f83
MD5 691cad4d647adf4dbbb7b958e6e8de82
BLAKE2b-256 61ed73e060a61ae0e3ca00bd85db10380f224410b25929f1b995a90d0f3a72f6

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page