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.1.1.tar.gz (3.1 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.1.1-py3-none-any.whl (3.1 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for agastya-1.1.1.tar.gz
Algorithm Hash digest
SHA256 f98be8b20faeb57cbe05a49f6da6025c06b7238542b6923925b06078190d8bef
MD5 4b1d45ac43ffdf8eeb676c5a1bea7ee3
BLAKE2b-256 b1abe07e7fc494279fc46b7438fa0bd7c2271264ba4befedd0b5492638adcc4e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: agastya-1.1.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.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f35641b7fe6fe974e74cb89007ab88961410a8d46e36b5b1839c97d66f660776
MD5 afae9bc577c2095d226b95f443ec01c5
BLAKE2b-256 b9309ea2bd93aa89ebb599632f81eab69c26550af8b87012291fb2b034ceffbd

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