Qianfan Python SDK

The Python SDK for Baidu's Qianfan large-model (MaaS) platform, including ERNIE models.

SDK
PyPI
v0.4.12.3
383stars
Apache License 2.0

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
53/100Fair
Development Activity0
Maintenance48
Community76
Maturity48
Momentum40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
77/100Good
Architecture80
Code Quality78
Innovation68
Learning Curve70

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.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search