Skip to main content

Makra SDK for Python - Web scraping and data extraction made simple

Project description

Makra SDK for Python

The official Python SDK for Makra - web scraping and data extraction made simple.

Installation

pip install makra

Quick Start

from makra import Makra

makra = Makra(api_key="your-api-key")

# Extract data with a query
result = await makra.extract(
    urls=["https://example.com"],
    query="Get all product titles and prices"
)

Features

  • Simple API: Easy-to-use async interface for web scraping
  • Schema-based Extraction: Define JSON schemas to extract structured data
  • Query-based Extraction: Use natural language to describe what to extract
  • Multiple Output Formats: Get content as markdown or plain text
  • Multiple Providers: Support for various LLM providers (Groq, Google AI)
  • Type-safe: Full type hints and Pydantic models
  • Crawling: Discover and extract links from pages
  • Page Mapping: Get structured maps of page content

API Reference

Initialize Client

from makra import Makra

makra = Makra(api_key="your-api-key")

With custom base URL:

makra = Makra(
    api_key="your-api-key",
    base_url="https://custom-api.example.com",
    api_version="v1"
)

Extract Data

Using a JSON schema:

schema = {
    "type": "object",
    "properties": {
        "title": {"type": "string"},
        "price": {"type": "number"}
    }
}

result = await makra.extract(
    urls=["https://example.com/products"],
    schema=schema
)

Using a natural language query:

result = await makra.extract(
    urls=["https://example.com/products"],
    query="Get all product titles and prices"
)

With actions (navigation, pagination):

from makra import enums

result = await makra.extract(
    urls=["https://example.com"],
    schema=schema,
    actions=[enums.ACTION.NAVIGATION, enums.ACTION.PAGINATION]
)

With extract options:

from makra import types

options = types.ExtractOptions(
    disable_cache=True,
    disable_pagination=False
)

result = await makra.extract(
    urls=["https://example.com"],
    query="Get products",
    options=options
)

Format Content

As markdown:

content = await makra.format(
    urls=["https://example.com"],
    type="markdown"
)

As text:

content = await makra.format(
    urls=["https://example.com"],
    type="text"
)

Using enum:

from makra import enums

content = await makra.format(
    urls=["https://example.com"],
    type=enums.FORMAT_TYPE.MARKDOWN
)

Crawl URLs

links = await makra.crawl(urls=["https://example.com"])

With options:

from makra import types

options = types.CrawlOptions()
links = await makra.crawl(
    urls=["https://example.com"],
    options=options
)

Page Map

page_map = await makra.page_map(urls=["https://example.com"])

Pre-process

result = await makra.pre_process(urls=["https://example.com"])

With options:

from makra import types

options = types.PreprocessOptions()
result = await makra.pre_process(
    urls=["https://example.com"],
    options=options
)

Ping API

status = await makra.ping()

Using Providers

With Groq:

from makra import Makra, providers

groq_provider = providers.Groq(api_key="your-groq-api-key")

makra = Makra(
    api_key="your-makra-api-key",
    provider=groq_provider
)

With Google AI:

from makra import Makra, providers

google_provider = providers.GoogleAI(api_key="your-google-api-key")

makra = Makra(
    api_key="your-makra-api-key",
    provider=google_provider
)

Custom model:

groq_provider = providers.Groq(
    api_key="your-groq-api-key",
    model="llama-3-70b-8192"
)

Types and Enums

Import types:

from makra import types

options = types.ExtractOptions(disable_cache=True)

Import enums:

from makra import enums

# Format types
enums.FORMAT_TYPE.MARKDOWN
enums.FORMAT_TYPE.TEXT

# Actions
enums.ACTION.NAVIGATION
enums.ACTION.PAGINATION

Error Handling

from makra.errors import RequestError

try:
    result = await makra.extract(urls=["https://example.com"], query="...")
except RequestError as e:
    print(f"Error {e.status_code}: {e.message}")

Requirements

  • Python 3.12+
  • An active Makra API key

License

MIT License - see LICENSE for details.

Links

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

sdk_makra_ritsource-0.1.0.tar.gz (6.6 kB view details)

Uploaded Source

Built Distribution

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

sdk_makra_ritsource-0.1.0-py3-none-any.whl (10.7 kB view details)

Uploaded Python 3

File details

Details for the file sdk_makra_ritsource-0.1.0.tar.gz.

File metadata

  • Download URL: sdk_makra_ritsource-0.1.0.tar.gz
  • Upload date:
  • Size: 6.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for sdk_makra_ritsource-0.1.0.tar.gz
Algorithm Hash digest
SHA256 e2e968b8b0857a59fc15cd48badfffa28c9140db089c565f5fc7acdd1a325bd3
MD5 1588695eceda295071689eb92b31886a
BLAKE2b-256 73361de50f98940728422d6bbfb6fdbed37e7657d1a9a3fc794c2024b1e8b4cf

See more details on using hashes here.

File details

Details for the file sdk_makra_ritsource-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for sdk_makra_ritsource-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a1267f2f2fc6203482eca699103a3578db3f28d1b9c55f87e4d1dc10c1efbff7
MD5 10974debb94f89151f91b214b0918db8
BLAKE2b-256 ac0510245b26d9aa99e432b95390d2e607f3c5477abc3ded91c7eb4207b72b6f

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