Skip to main content

Python client SDK for Middleman.ai API

Project description

Middleman.ai Python SDK

Middleman.ai の API を簡単に利用するための Python SDK です。マークダウン →PDF 変換、JSON→PPTX 変換、PDF ページ → 画像変換などの機能を提供します。

インストール

pip install middleman-ai

基本的な使い方

from middleman_ai import ToolsClient

# クライアントの初期化
client = ToolsClient(api_key="YOUR_API_KEY")

# Markdown → PDF変換
markdown_text = "# Sample\nThis is a test."
pdf_url = client.md_to_pdf(markdown_text, pdf_template_id="template-uuid")
print(f"Generated PDF URL: {pdf_url}")

CLI の使用方法

SDK はコマンドラインインターフェース(CLI)も提供しています。UV を使用して以下のように実行できます:

# APIキーの設定
export MIDDLEMAN_API_KEY=your-api-key

# Markdown → PDF変換
echo "# テスト" | uvx middleman md-to-pdf [テンプレートID]

# Markdown → DOCX変換
echo "# テスト" | uvx middleman md-to-docx

# PDF → ページ画像変換
uvx middleman pdf-to-page-images input.pdf

# DOCX → ページ画像変換
uvx middleman docx-to-page-images input.docx

# PPTX → ページ画像変換
uvx middleman pptx-to-page-images input.pptx

# XLSX → ページ画像変換
uvx middleman xlsx-to-page-images input.xlsx

# PPTXテンプレート解析
uvx middleman json-to-pptx-analyze [テンプレートID]

# PPTXテンプレート実行
echo '{"slides":[{"type":"title","placeholders":[{"name":"title","content":"テストタイトル"}]}]}' | \
uvx middleman json-to-pptx-execute [テンプレートID]

# Mermaid図表 → 画像変換
echo "graph TD; A-->B" | uvx middleman mermaid-to-image

各コマンドは標準入力からテキストを受け取るか、必要に応じてファイルパスやテンプレート ID を引数として受け取ります。

MCP Server

Middleman SDK は MCP サーバーを提供し、Claude Desktop アプリケーションなどから利用できます。

Claude Desktop 設定

Claude Desktop アプリケーションのclaude_desktop_config.jsonを以下のように設定します:

{
  "mcpServers": {
    "middleman": {
      "command": "uvx",
      "args": ["--from", "middleman-ai", "mcp-server"],
      "env": {
        "MIDDLEMAN_API_KEY": "xxxxx"
      }
    }
  }
}

エラーハンドリング

from middleman_ai import ToolsClient, NotEnoughCreditError

client = ToolsClient(api_key="YOUR_API_KEY")

try:
    pdf_url = client.md_to_pdf("# Test")
except NotEnoughCreditError:
    print("クレジット不足です。プランをアップグレードしてください。")
except Exception as e:
    print(f"エラーが発生しました: {e}")

ライセンス

MIT License

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

middleman_ai-0.3.2.tar.gz (2.1 MB view details)

Uploaded Source

Built Distribution

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

middleman_ai-0.3.2-py3-none-any.whl (17.7 kB view details)

Uploaded Python 3

File details

Details for the file middleman_ai-0.3.2.tar.gz.

File metadata

  • Download URL: middleman_ai-0.3.2.tar.gz
  • Upload date:
  • Size: 2.1 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.7

File hashes

Hashes for middleman_ai-0.3.2.tar.gz
Algorithm Hash digest
SHA256 5da4953de6f7e82280b928d1712ee056cdab1a93c91ce236f89a6b5794823000
MD5 b499a1fa500d474091fc91838ce5feda
BLAKE2b-256 dd30e191d00f4b50563e4bd49650e3dff151eed383f0eb7a78226911003b1c31

See more details on using hashes here.

File details

Details for the file middleman_ai-0.3.2-py3-none-any.whl.

File metadata

  • Download URL: middleman_ai-0.3.2-py3-none-any.whl
  • Upload date:
  • Size: 17.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.7

File hashes

Hashes for middleman_ai-0.3.2-py3-none-any.whl
Algorithm Hash digest
SHA256 ff0a43a2a005eb7bbb8fe000ccf2cf5f80d83750848b9701aae062f6f205d404
MD5 334bc23ce20501e1e6330fde594120fa
BLAKE2b-256 21e61d81e59bc38b6e0b1eec6e2671e9c1eae46efec79004250dfa3b4a661158

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