Skip to main content

A lightweight Python SDK for web scraping, data cleaning, and CSV/Excel export.

Project description

MFDev Scraper SDK

A lightweight Python SDK for web scraping and data processing.
It provides robust HTTP request handling, data cleaning utilities, and convenient export helpers for CSV and Excel formats.

Features

  • 🚀 HTTP Requests with Retry Logic
    Reliable GET/POST requests with configurable retries, custom error handling, and browser impersonation support (via curl_cffi).

  • 🛡️ Custom Exceptions
    Clear and descriptive errors for configuration issues, HTTP status mismatches, max retries exceeded, invalid dictionaries, and file I/O errors.

  • 🧹 Data Cleaning
    Utility to remove duplicates from lists of dictionaries, with strict or lenient validation modes.

  • 📊 Data Export
    Export your data directly to CSV or Excel with built-in helpers.


Installation

You can install directly from source:

pip install -e .

Or once published to PyPI:

pip install mfdev-scraper



Usage - Example

Import

  from mfdev_scraper_sdk import MFDevScraper

  scraper = MFDevScraper()

Use request_mfdev method

  '''
  Perform a Request

  You can perform a request using the request_mfdev method.
  This method allows you to customize parameters such as:

  * status_code_accepted → The HTTP status code considered a successful response.

  * max_retries → The maximum number of retry attempts if the request fails.

  * timeout → The time (in seconds) to wait before the request times out.

  Note: If you do not provide these parameters, the method will automatically use the default values.

  '''

  # Perform a GET request
  response = client.request_mfdev(
      method="GET",
      url="https://httpbin.org/get",
      status_code_accepted=200,   # optional
      max_retries=3,              # optional
      timeout=10.0                # optional
  )

  print("Status Code:", response.status_code)
  print("Response Body:", response.text)

Use clean_duplicates_dict method

  '''
  Clean Duplicate Records

  The clean_duplicates_dict method removes duplicate records from a list of dictionaries.

  field → The key used to check for duplicates.

  If not provided, the default value is "id".

  strict → Defines how to handle records missing the specified field.

  Default: True → Raises an error if the field does not exist.

  If set to False, records without the field will simply be ignored.

  '''

  # Example data with duplicates - strict = False
  records = [
      {"id": 1, "name": "Alice"},
      {"id": 2, "name": "Bob"},
      {"id": 1, "name": "Alice"},   # Duplicate
      {"id": 3, "name": "Charlie"},
      {"name": "No ID"}             # Missing field
  ]

  # Clean duplicates by "id"
  cleaned = client.clean_duplicates_dict(records, field="id", strict=False)

  print("Cleaned Records:")
  for item in cleaned:
      print(item)

  # Output (with strict=False)
  '''
  {'id': 1, 'name': 'Alice'}
  {'id': 2, 'name': 'Bob'}
  {'id': 3, 'name': 'Charlie'}
  {'name': 'No ID'}

  '''

  ## Example data with duplicates - strict = true

  records = [
      {"id": 1, "name": "Alice"},
      {"name": "No ID"}   # Missing "id"
  ]

  try:
      # This will raise an error because "id" is missing in one record
      cleaned = client.clean_duplicates_dict(records, field="id", strict=True)
  except DataValidationError as e:
      print("Error:", e)

  # Output (with strict=True)
  '''
  Error: Missing required field 'id' in record

  '''

Use generate_csv method

  '''
  Export to CSV

  To export your data to a CSV file, simply provide the file name without the extension.
  Optionally, you can also specify a folder where the file will be saved.

  '''

  csv_path = scraper.generate_csv(cleaned, "output")
  print(f"CSV saved at: {csv_path}")

Use generate_excel method

  '''
  Export to Excel

  To export your data to a Excel file, simply provide the file name without the extension.
  Optionally, you can also specify a folder where the file will be saved.

  '''
  excel_path = scraper.generate_excel(cleaned, "output", "files")
  print(f"Excel saved at: {excel_path}")



Custom Errors

The SDK exposes several custom exceptions you can catch:

  • ConfigurationError
  • RequestError
  • HTTPStatusError
  • MaxRetriesExceeded
  • InvalidResponseError
  • DataValidationError
  • MissingFieldError
  • NotADictError
  • FileIOError
  • CSVWriteError
  • ExcelWriteError

Development

Clone the repository and install dependencies:

git clone https://github.com/yourusername/mfdev-scraper.git
cd mfdev-scraper
pip install -e .
pip install pytest

Run tests:

pytest -q

License

This project is licensed under the MIT License.


Author

Miguel Fernandez
Homepage: https://mfdev.vercel.app

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

mfdev_scraper-0.1.6.tar.gz (8.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mfdev_scraper-0.1.6-py3-none-any.whl (8.7 kB view details)

Uploaded Python 3

File details

Details for the file mfdev_scraper-0.1.6.tar.gz.

File metadata

  • Download URL: mfdev_scraper-0.1.6.tar.gz
  • Upload date:
  • Size: 8.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for mfdev_scraper-0.1.6.tar.gz
Algorithm Hash digest
SHA256 b0023b977844084c74c27973c1a235c97a6df56f5f5f0631ae02da667a007288
MD5 2761384971b86fc00dbc61bc055777bf
BLAKE2b-256 6d27b38aa79e8bed1bda8f74bb07d74b7b71a645d0995e2e187aa7cf5471d728

See more details on using hashes here.

File details

Details for the file mfdev_scraper-0.1.6-py3-none-any.whl.

File metadata

  • Download URL: mfdev_scraper-0.1.6-py3-none-any.whl
  • Upload date:
  • Size: 8.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for mfdev_scraper-0.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 efe649f96a3a4d94fb1b111e17dcbb9d89a83ae6fb8b4c231a5788c832a6e5eb
MD5 e8611d481adac9eff9b8698f4a9386b2
BLAKE2b-256 319b5a87d9bfd8a103018a7c6404abca445ef6f2df7e51ee47d09da224af6cdc

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