Skip to content

Conversation

@vishalg0wda
Copy link

@vishalg0wda vishalg0wda commented Jan 20, 2026

Summary

Migrates the SDK to use PEP 420 implicit namespace packages, enabling future mistralai.workflows subpackage to be managed separately.

Breaking Change: Import paths change from from mistralai import X to from mistralai.sdk import X

Changes

  • Configure moduleName: mistralai.sdk in gen.yaml for namespace package support
  • Generate SDK with new namespace structure (src/mistralai/sdk/)
  • Migrate custom code regions to new SDK location
  • Update import paths in extra/ package
  • Fix py.typed marker paths in pyproject.toml
  • Restore custom hooks (custom_user_agent, deprecation_warning, tracing)
  • Configure mypy for PEP 420 namespace packages

New Structure

src/mistralai/           # PEP 420 namespace (no __init__.py)
├── sdk/                 # Generated SDK
├── extra/               # Custom extensions
└── (future: workflows/) # Separately managed package

Test Plan

  • All existing tests pass
  • Package builds successfully (uv build)
  • Import paths verified working
  • pylint passes (10.00/10)
  • mypy passes (no issues in 304 source files)
  • Published to test PyPI and verified installation

Test PyPI Verification

Published and tested at: https://test.pypi.org/project/mistralai/1.11.0/

# Install from test PyPI
uv pip install --index-strategy unsafe-best-match \
  --index-url https://test.pypi.org/simple/ \
  --extra-index-url https://pypi.org/simple/ \
  mistralai==1.11.0

# Verified imports work correctly
python -c "from mistralai.sdk import Mistral; print(Mistral)"
# <class 'mistralai.sdk.sdk.Mistral'>

python -c "from mistralai.sdk.models import ChatCompletionRequest; print(ChatCompletionRequest)"
# <class 'mistralai.sdk.models.chatcompletionrequest.ChatCompletionRequest'>

Migration Guide

# Before (v1.x)
from mistralai import Mistral
from mistralai.models import ChatCompletionRequest

# After (v2.x)
from mistralai.sdk import Mistral
from mistralai.sdk.models import ChatCompletionRequest

Add moduleName: mistralai.sdk to enable implicit namespace packages,
allowing mistralai.workflows to be managed separately.

Changes:
- gen.yaml: Add moduleName config, bump version to 2.0.0
- docs: Add migration plan and Speakeasy feature request templates

Breaking change: imports will change from `from mistralai import X`
to `from mistralai.sdk import X`
Speakeasy regeneration with moduleName: mistralai.sdk creates:
- src/mistralai/sdk/ - new SDK location (namespace subpackage)
- src/mistralai/ - namespace root (no __init__.py)

Custom code regions migrated:
- sdk/chat.py: parse, parse_async, parse_stream, parse_stream_async
- sdk/conversations.py: run_async, run_stream_async

Extra package imports updated to use mistralai.sdk:
- mistralai.sdk.models instead of mistralai.models
- mistralai.sdk.types instead of mistralai.types
- mistralai.sdk.utils instead of mistralai.utils

Breaking change: imports now require mistralai.sdk prefix
Update remaining relative imports (..models, ...types) to absolute
imports (mistralai.sdk.models, mistralai.sdk.types) to work with
the new PEP 420 namespace package structure.
Update force-include and package-data paths from src/mistralai/py.typed
to src/mistralai/sdk/py.typed to match new namespace package layout.
Migrate custom hooks (custom_user_agent, deprecation_warning, tracing)
to new sdk/_hooks location. Update import path in tracing.py to use
absolute import for mistralai.extra.observability.otel.
- Add pylint disable comments for intentional lazy imports
- Use lazy % formatting in logging calls
- Remove unnecessary else after break statements
Add namespace_packages and explicit_package_bases settings to resolve
duplicate module name errors when running mypy with src in the path.
Update generated lock files and fix minor formatting in conversations.py.
@louis-sanna-dev louis-sanna-dev self-assigned this Jan 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants