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

Uploaded Python 3

File details

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

File metadata

  • Download URL: middleman_ai-0.3.0.tar.gz
  • Upload date:
  • Size: 2.0 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.0.tar.gz
Algorithm Hash digest
SHA256 62bf4434c4fe323e1fadd72b209f07ce2edf1d8e0130adfb68c1f0c4c5f2b2a3
MD5 7c5368d9646af2650b6f23fc5a9a1353
BLAKE2b-256 869ae12f45002923667d34374c34b9c953f41996fe2503213017e21662519726

See more details on using hashes here.

File details

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

File metadata

  • Download URL: middleman_ai-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 16.9 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8957ddf4958ac83a7bea9a44c86ccab96d11c4098369dd986160a829566b81af
MD5 75e6049b6d2b72e93b9d2a81e1a13cbb
BLAKE2b-256 c4da1ac198b35bbc6b365b424b9269aca704e9185ff97fd71006a583b779a0e1

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