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]

各コマンドは標準入力からテキストを受け取るか、必要に応じてファイルパスやテンプレート 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.1.0.tar.gz (2.7 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.1.0-py3-none-any.whl (22.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: middleman_ai-0.1.0.tar.gz
  • Upload date:
  • Size: 2.7 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.1.0.tar.gz
Algorithm Hash digest
SHA256 6103cabf72f7cf0fec5af6b548c2c35da7797a5a8ba7edb0e9c3a3d71a5ca21a
MD5 09234cc18c880dbb94f0cacc9bce1524
BLAKE2b-256 87a739c73c4ab16c2b7d370c4f1d153e032e0be367af4882be8f9cd7a1af6ac8

See more details on using hashes here.

File details

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

File metadata

  • Download URL: middleman_ai-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 22.5 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.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1505b1e27a051f86a22fbc9d506bdc0e823faad249a60adbf2fe00d59d6187cf
MD5 30ce4b584d3b7b86415d32fa725ed415
BLAKE2b-256 37e19b6ba0a8879c044bf5bed6cdd9e276dffdcf98e528e9296dfa31ecba01b9

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