qianfan
文心千帆大模型平台 Python SDK
What it is and what it does
Qianfan is Baidu's official Python SDK for accessing the Qianfan large language model platform. It wraps HTTP and async HTTP calls to Baidu's inference, training, and model management services, handling authentication, request formatting, and response parsing. The SDK supports multiple authentication modes (Access Key/Secret Key or legacy API Key/Secret Key) and exposes high-level interfaces for chat, text completion, embeddings, image generation, and model lifecycle operations.
The package is designed for developers integrating Baidu's LLM capabilities into Python applications. It manages 16 runtime dependencies including requests, aiohttp, pydantic for validation, tenacity for retry logic, and rich for CLI output. Configuration is flexible—credentials can be set via environment variables, .env files, or code. The SDK also provides tokenization utilities, rate limiting, and prompt management, making it a comprehensive client for the Qianfan ecosystem.
Use it for:
- Build chatbot or conversational AI applications using ERNIE models via the ChatCompletion interface.
- Generate text embeddings for semantic search, clustering, or retrieval-augmented generation workflows.
- Fine-tune Baidu's large language models on custom datasets using the model training API.
- Generate images from text prompts using the Text2Image capability within the Qianfan platform.
- Manage datasets, models, and deployments programmatically through the model management and service APIs.
- Integrate Qianfan's plugin ecosystem and external tools into Python applications via the plugin interface.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Python SDK for Baidu Qianfan large language model platform, enabling chat, text completion, embeddings, image generation, model training, and dataset management through a unified API.
Yes, with conditions. Install if you are building on Baidu's Qianfan platform and need a Python client—the SDK is officially maintained, permissively licensed, and has low install friction. However, note that maintenance is aging (553 days since last release), so verify that the current version supports your target models and features before committing to production. No known security vulnerabilities as of the last OSV check.
Install
qianfan on PyPI
pip
pip install qianfanuv
uv add qianfanpoetry
poetry add qianfanInstalling qianfan
Before you install
Low install friction with a pure-Python wheel distribution. Maintenance status is aging—last commit was 2025-12-12 and the package has not received a release in 553 days, though the repository remains active and not archived.
License in practice
Licensed under Apache-2.0 (permissive), allowing commercial use, modification, and distribution with minimal restrictions—suitable for most production and proprietary projects.
Quickstart
pip install qianfan
import os
import qianfan
os.environ["QIANFAN_ACCESS_KEY"] = "..."
os.environ["QIANFAN_SECRET_KEY"] = "..."
chat_comp = qianfan.ChatCompletion(model="ERNIE-4.0-8K")
resp = chat_comp.do(messages=[{"role": "user", "content": "hello"}])
print(resp["result"])
Requires Python 3.7 or higher; Baidu Qianfan platform credentials (Access Key and Secret Key) must be obtained from Baidu Cloud console and set as environment variables.
Verify before relying
- Whether the aging maintenance status (553 days since last release) affects stability or feature parity with the Baidu platform.
- Performance characteristics and rate-limiting behavior under high-concurrency workloads given the aiolimiter dependency.
- Whether all 16 runtime dependencies are actively maintained and free of known vulnerabilities beyond the OSV check.
Package facts
| License | Apache-2.0 (permissive) |
| Python support | supports the current Python release (<4,>=3.7) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 16 — requests, aiohttp, aiolimiter, importlib-metadata, bce-python-sdk, typing-extensions, pydantic, python-dotenv, tenacity, multiprocess, rich, typer, pyyaml, prompt-toolkit, diskcache, cachetools |
| Maintenance | aging — 553 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 234,138/month — #9,028 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: qianfan-0.4.12.3-py3-none-any.whl
Keywords: baidu, qianfan
Tags
More Artificial Intelligence packages
LiteLLM provides a unified Python interface to…
permissive · top 100 on PyPI
huggingface-hubClient library and CLI tool for downloading,…
permissive · top 100 on PyPI
langchainLangChain provides a framework for building…
permissive · top 1,000 on PyPI
hf-xethf-xet provides chunk-based deduplication and…
permissive · top 1,000 on PyPI
tokenizersTokenizers converts raw text into token…
permissive · top 1,000 on PyPI
transformersTransformers provides a unified framework for…
permissive · top 1,000 on PyPI
aistudio-sdkPython client library for the AIStudio API,…
permissive · top 5,000 on PyPI
langchain-ibmIntegrates IBM watsonx.ai models with…
permissive · top 15,000 on PyPI
volcengineVolcengine SDK for Python provides client…
permissive · top 15,000 on PyPI
langchainplus-sdkClient library for connecting to LangSmith, a…
permissive · top 15,000 on PyPI
ai21Python SDK for accessing AI21 Labs' language…
unclear · top 15,000 on PyPI
zai-sdkOfficial Python SDK for Z.ai's large model…
unclear · top 15,000 on PyPI
gigachatPython SDK for the GigaChat REST API, a large…
permissive · top 15,000 on PyPI
ollamaProvides a Python client to interact with…
permissive · top 5,000 on PyPI
volcengine-python-sdkPython SDK for Volcengine cloud services,…
permissive · top 15,000 on PyPI
zhipuaiOfficial Python SDK for ZhipuAI's large model…
unclear · top 15,000 on PyPI