Exporting Python Code & Standalone Models
Learn how to export transparent, standalone Python scripts, Scikit-Learn/LightGBM pipelines, and FastAPI server code with zero vendor lock-in.
Zero Lock-in Guarantee: Doushi is committed to code transparency. Every model you generate can be downloaded as a complete, standalone Python repository with Scikit-Learn pipelines, serialized weights, and a production FastAPI service.
Why Code Export Matters
Vendor lock-in is a primary obstacle when adopting cloud AI platforms. If an enterprise must migrate to an on-premises cluster, air-gapped environment, or private VPC, you should never lose access to your trained models.
With Doushi, you own 100% of the model weights and the exact Python source code that produced them.
How to Export Your Model
You can export your code and model artifacts in two ways:
- Via the Web Dashboard:
In your project dashboard, navigate to the Code tab to inspect the auto-generated code. Click Download Code to download the standalone Python training script (pipeline_<project_id>.py). - Via the Official CLI (
doushi export):
To download the full deployment bundle including the trained weights and FastAPI serving microservice, run:doushi export <YOUR_PROJECT_ID> --out ./doushi-model-bundle
What is Included in the Export Bundle
The CLI export generates a complete, self-contained directory:
doushi-model-bundle/
├── model.pkl # Serialized champion model & sklearn ColumnTransformer pipeline
├── pipeline.py # Self-contained script to train the model from scratch
├── serve.py # Production FastAPI REST microservice
├── Dockerfile # Container definition to build and deploy anywhere
├── requirements.txt # Fixed, audited Python dependencies
├── metadata.json # Project schema, hyperparameters, and evaluation metrics
└── README.md # Local setup and deployment instructions
[!NOTE] Serialization & Format Support: Preprocessing pipelines (including imputers, one-hot/ordinal encoders, and scalers) and estimators are serialized together into
model.pklusingjoblibandcloudpicklefor zero-overhead inference. Native ONNX runtime format export is currently in development on our roadmap.
Inspecting the Exported Code
1. pipeline.py (Reproducible Training)
"""
Auto-generated by doushi.ai
Dataset: customers.csv
Model Architecture: LightGBMClassifier in an end-to-end sklearn Pipeline
"""
import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.pipeline import Pipeline
from sklearn.compose import ColumnTransformer
from sklearn.preprocessing import StandardScaler, OneHotEncoder
from sklearn.impute import SimpleImputer
from lightgbm import LGBMClassifier
import joblib
# 1. Load dataset
df = pd.read_csv("customers.csv")
target_col = "churned"
X = df.drop(columns=[target_col, "customer_id"])
y = df[target_col]
numeric_features = X.select_dtypes(include=["int64", "float64"]).columns.tolist()
categorical_features = X.select_dtypes(include=["object", "category"]).columns.tolist()
# 2. Build preprocessing pipeline
preprocessor = ColumnTransformer(
transformers=[
("num", Pipeline([
("imputer", SimpleImputer(strategy="median")),
("scaler", StandardScaler())
]), numeric_features),
("cat", Pipeline([
("imputer", SimpleImputer(strategy="most_frequent")),
("encoder", OneHotEncoder(handle_unknown="ignore"))
]), categorical_features)
]
)
# 3. Assemble full pipeline
pipeline = Pipeline([
("preprocessor", preprocessor),
("classifier", LGBMClassifier(
n_estimators=100,
learning_rate=0.05,
max_depth=6,
random_state=42
))
])
# 4. Train/Test split and fit
X_train, X_test, y_train, y_test = train_test_split(
X, y, test_size=0.2, random_state=42, stratify=y
)
pipeline.fit(X_train, y_train)
# 5. Save self-contained pipeline
joblib.dump(pipeline, "model.pkl")
print("Model pipeline trained and saved to model.pkl successfully.")
2. Running the Exported FastAPI Server Locally
You can spin up your own local REST API server without connecting to Doushi:
cd doushi-model-bundle/
pip install -r requirements.txt
uvicorn serve:app --host 127.0.0.1 --port 8000
# or simply: python serve.py
Send a test prediction request:
curl -X POST http://127.0.0.1:8000/predict \
-H "Content-Type: application/json" \
-d '{"monthly_spend": 85.0, "tenure_months": 12, "support_tickets": 2, "contract_type": "month-to-month"}'
Response:
{
"predictions": [0]
}
Commercial Licensing & IP Ownership
All exported scripts and model weights are licensed under the Apache 2.0 License or proprietary to your organization. You may redistribute, package into commercial software, or deploy on your own clouds with no royalties or usage fees.
