> ## Documentation Index
> Fetch the complete documentation index at: https://docs.somark.cn/llms.txt
> Use this file to discover all available pages before exploring further.

# SoMark SDK

> 使用 SoMark SDK 在 Python 或 JavaScript 项目里完成文档解析集成。

适合把解析能力接进产品、后端服务和自动化系统。如果你还在比较接入方式，先看 [入门总览](/documentation/get-started-overview)；如果你只是想先在终端跑通一次，去看 [SoMark CLI](/documentation/cli)。

<Steps>
  <Step title="安装 SDK">
    SoMark 提供 Python 和 JavaScript 两个实现。

    <CodeGroup>
      ```bash Python theme={null}
      pip install somark
      ```

      ```bash JavaScript theme={null}
      npm install somark-js
      ```
    </CodeGroup>
  </Step>

  <Step title="初始化客户端">
    最简单的方式是在初始化时直接传入 API Key。

    <CodeGroup>
      ```python Python theme={null}
      from somark import SoMark

      client = SoMark(api_key="sk-your-api-key")
      ```

      ```typescript JavaScript theme={null}
      import { SoMark } from 'somark-js'

      const client = new SoMark({ apiKey: 'sk-your-api-key' })
      ```
    </CodeGroup>
  </Step>

  <Step title="先完成一次同步解析">
    先拿一个文件跑通结果，再决定要不要补充格式、配置和后处理逻辑。

    <CodeGroup>
      ```python Python theme={null}
      response = client.parser.parse(
          file="./document.pdf",
          formats=["md", "json"],
      )
      response.save("./document.md")
      ```

      ```typescript JavaScript theme={null}
      const response = await client.parser.parse({
        file: './document.pdf',
        formats: ['md', 'json'],
      })

      await response.save('./document.md')
      ```
    </CodeGroup>
  </Step>

  <Step title="大文件改用异步任务">
    长文档、批量任务和后台流程更适合异步模式。

    <CodeGroup>
      ```python Python theme={null}
      task = client.parser.parse_async(file="./large.pdf", formats=["md"])
      result = task.wait()
      result.save("./large.md")
      ```

      ```typescript JavaScript theme={null}
      const task = await client.parser.parseAsync({
        file: './large.pdf',
        formats: ['md'],
      })

      const result = await task.wait()
      await result.save('./large.md')
      ```
    </CodeGroup>

    需要更完整的参数和错误处理说明时，继续看 [CLI & SDK 使用指南](/cli-sdk/usage)。
  </Step>
</Steps>
