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

makra-0.0.2.tar.gz (6.5 kB view details)

Uploaded Source

Built Distribution

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

makra-0.0.2-py3-none-any.whl (10.5 kB view details)

Uploaded Python 3

File details

Details for the file makra-0.0.2.tar.gz.

File metadata

  • Download URL: makra-0.0.2.tar.gz
  • Upload date:
  • Size: 6.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for makra-0.0.2.tar.gz
Algorithm Hash digest
SHA256 98462ee0c69619007b8235ebdbab62306600a7d5781467b8ee46b92f3fd9c7a0
MD5 4fe9c8e8766d501d03f84fba0aeb702a
BLAKE2b-256 dc98a231351f22b910d1aa4670df46991a37944e35c14b47aa098a91cb3199fd

See more details on using hashes here.

File details

Details for the file makra-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: makra-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 10.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for makra-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 bce57caa208f0f88e946a35a62961dc048322809c6f9f65bd5bca85fa1df48d9
MD5 3ced359c4109d8434e498fc5eb5a207a
BLAKE2b-256 688a2f15f25b0d47c41f219a2e9acb87c9d3b29121c1297b82c7cd2d5c628409

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