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.1.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.1-py3-none-any.whl (17.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: middleman_ai-0.3.1.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.1.tar.gz
Algorithm Hash digest
SHA256 0c618309255af5b45549cea2b167a0a106c9811f218a232bacf4231feabfb3f2
MD5 70da92617777f813c02332b414d74fa6
BLAKE2b-256 fa28e4f048087d464d35111a05fc44a76041b9d3507002d88fc352829359f3af

See more details on using hashes here.

File details

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

File metadata

  • Download URL: middleman_ai-0.3.1-py3-none-any.whl
  • Upload date:
  • Size: 17.6 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ab625e7fdba8ba95c45478a6c586f1b99565a97834a02b0db4fcf015585bbc2f
MD5 e09a4e3488af33917d6b87ab3962c6f1
BLAKE2b-256 4794afed238453f4f03fabd019324d52e59ee5e6771a2ddb027b654d447886d3

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