Skip to main content

High-performance web scraping and MongoDB utilities

Project description

Agastya

High-performance web scraping and MongoDB utilities for Python.

Features

  • CustomLogger: Fast, color-coded logging with minimal overhead
  • Record: Lightweight MongoDB document wrapper with state management
  • fetch(): Smart HTTP client with caching, retries, and validation
  • clean_dict(): Comprehensive text/HTML cleaning utilities
  • run_engine(): Adaptive concurrent task executor with auto-scaling threads

Installation

pip install agastya

Quick Start

Basic Usage

from agastya import fetch, CustomLogger, Record

# Initialize logger
logger = CustomLogger(name=__file__)

# Fetch with caching
response = fetch(
    url="https://example.com",
    save_dir="cache",
    filename="page.html",
    max_retries=3
)

# Work with MongoDB records
from pymongo import MongoClient
db = MongoClient()['mydb']
collection = db['items']

doc = collection.find_one({"_id": "123"})
record = Record(doc, collection, logger)

# Mark states
record.mark_done("scraped", meta={"items": 42})
record.mark_fail("parsed", meta={"error": "timeout"})

Configuration

Create a config.py in your project root:

from pymongo import MongoClient

client = MongoClient("mongodb://localhost:27017")
db = client['your_database']

Advanced Features

Smart caching with validation:

response = fetch(
    url="https://example.com/data",
    save_dir="cache",
    filename="data.html",
    valid_rules={
        "required": ["expected text"],
        "forbidden": ["error", "404"],
        "remove": True  # delete invalid cache
    }
)

Concurrent processing:

from agastya import run_engine
from pymongo import MongoClient

db = MongoClient()['mydb']
collection = db['tasks']

def worker(doc):
    # Process document
    print(f"Processing {doc['_id']}")

query = {"status": "pending"}
run_engine(collection, query, worker, THREADS_START=50)

Requirements

  • Python 3.8+
  • requests
  • lxml
  • pymongo
  • urllib3

Development

# Clone repository
git clone https://github.com/yourusername/agastya.git
cd agastya

# Install in editable mode with dev dependencies
pip install -e ".[dev]"

# Run tests
pytest

License

MIT License - see LICENSE file for details

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

agastya-1.2.1.tar.gz (3.2 kB view details)

Uploaded Source

Built Distribution

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

agastya-1.2.1-py3-none-any.whl (3.1 kB view details)

Uploaded Python 3

File details

Details for the file agastya-1.2.1.tar.gz.

File metadata

  • Download URL: agastya-1.2.1.tar.gz
  • Upload date:
  • Size: 3.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.6

File hashes

Hashes for agastya-1.2.1.tar.gz
Algorithm Hash digest
SHA256 bcd16612ca79fb92605ffbf9d990ded0a67f1a6aec193c9e4449dbd687fbf945
MD5 5f1a1e65717a63fe3b4d629fe0ca0ea1
BLAKE2b-256 0369495a2caa9fb06ca52161b801bbcdd5a832103cca81109633b80c1b0f9131

See more details on using hashes here.

File details

Details for the file agastya-1.2.1-py3-none-any.whl.

File metadata

  • Download URL: agastya-1.2.1-py3-none-any.whl
  • Upload date:
  • Size: 3.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.6

File hashes

Hashes for agastya-1.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 2a325c5cb004da2e61dc7b1fa824e83dcac135056656a78ffb1974e9bd014fa9
MD5 ebfd964f8dd89595eb5db9a898adabb8
BLAKE2b-256 fbc4f38bf76862d280ec42b54510d1093befb1fbe0ade28150c4b5910ec75a03

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