Qianfan Python SDK
The Python SDK for Baidu's Qianfan large-model (MaaS) platform, including ERNIE models.
Repository Health
Technical Analysis
Qianfan is the official Python SDK for Baidu’s Qianfan Model-as-a-Service (MaaS) platform, providing convenient programmatic access to Baidu’s large models such as the ERNIE family. It exposes chat completions, text completions, and embeddings, along with higher-level tooling for datasets, model training and fine-tuning, evaluation, and LMOps best practices.
Using Access Key and Secret Key credentials from the Baidu Cloud console, developers can call hosted ERNIE models directly, batch-process data, and manage the full model lifecycle. The SDK covers both the inference resources and an opinionated trainer/dataset/evaluation stack for teams building on the Qianfan platform.
What You Get
- ChatCompletion, Completion, and Embedding clients for Baidu’s hosted large models
- Credential-based authentication via Access Key / Secret Key from Baidu Cloud
- Dataset, trainer, and evaluation modules for fine-tuning and assessing models
- LMOps utilities and best-practice tooling for operating models on the Qianfan platform
Common Use Cases
- Calling ERNIE chat and completion models from Python applications
- Generating embeddings for search or RAG against Baidu-hosted models
- Fine-tuning, evaluating, and managing custom models on the Qianfan platform
Under The Hood
Architecture - The Python package (in the python/ directory of a multi-language monorepo) is layered: resources holds the low-level API clients (ChatCompletion, Completion, Embedding and related model endpoints), config.py and consts.py centralize credentials and platform constants, and higher-level modules - dataset, trainer, evaluation, model, autotuner and common - build an LMOps workflow on top. A client subpackage handles HTTP, retries and auth signing against the Baidu Cloud API.
Tech Stack - Pure Python (3.7+) managed with Poetry, using pydantic-style config, requests/aiohttp-style HTTP, and optional pyarrow/dataset dependencies (with a fake_pyarrow_replacer fallback). Documentation is published on Read the Docs.
Code Quality - The repo ships a tests directory and a test_CI harness, uses a Makefile for tasks, and separates concerns cleanly between raw resources and the trainer/dataset layers. Recent development activity has slowed but the codebase is mature and typed (py.typed).
API Design - Basic inference is very approachable: set QIANFAN_ACCESS_KEY / QIANFAN_SECRET_KEY, construct ChatCompletion(model=…) and call do(messages=…). The trainer, dataset and evaluation APIs add more surface area and a steeper curve, but map onto Qianfan platform concepts and are documented with cookbooks.
Used by 2 apps in this directory
Langflow
AI Agents · AI Development
Build, test, and deploy AI agents and RAG workflows visually with native API and MCP server export.
MaxKB
AI Development · Knowledge Management
Build enterprise-grade AI agents with RAG, workflows & multi-modal support