KO
|
EN
gitlite — search
Search
#java
#php
#python
#android
#game
#c-plus-plus
#dsh-plugin
#tools
#hacktoberfest
#deepseek-harness
#dsh
#ruby
truss-go
★ 41
Open GitHub ↗
Golang SDK for Truss
Download README (.md)
Explore Similar Repositories
snippety
:
A wrapper class on top of SpannableStringBuilder with utility methods for android and custom spans.
fido-authenticator
:
FIDO authenticator Trussed app
VolumetricTruss
:
Source code for the paper "Volumetric Michell Trusses for Parametric Design and Fabrication" published at SCF 2019.
Python_Stable_3D_Truss_Analysis
:
slientruss3d : Python for stable truss analysis and optimization tool
InvertibleTrussDesign
:
Implementation of 'Inverting the structure-property map of truss metamaterials via deep learning' (PNAS)
// repository documentation
Was this content helpful?
★ 0
(0 ratings)
Select Rating:
★
★
★
★
★
Submit Feedback
Recent Feedback
×
Download README
Do you want to download the
README.md
file for
truss-go
?
Download (.md)
# truss-go > **Beta:** This SDK is in beta. APIs may change between versions. A Go SDK for deploying models to [Baseten](https://baseten.co) using [Truss](https://github.com/basetenlabs/truss). ## Installation ```bash go get github.com/basetenlabs/truss-go ``` ## Quick Start ```go package main import ( "context" "fmt" "log" "github.com/basetenlabs/truss-go" ) func main() { // Create client (reads BASETEN_API_KEY from environment) client := truss.NewClient() // Push a truss result, err := client.Push(context.Background(), "./my-truss", "my-model") if err != nil { log.Fatal(err) } fmt.Printf("Deployed! URL: %s\n", result.PredictURL()) } ``` ## Authentication The SDK supports three authentication methods: ```go // 1. Environment variable (recommended) // Set BASETEN_API_KEY in your environment client := truss.NewClient() // 2. Explicit API key client := truss.NewClient(truss.WithAPIKey("your-api-key")) // 3. From ~/.trussrc config file client, err := truss.NewClientFromConfig("baseten") ``` ### Config File Format The `~/.trussrc` file uses INI format: ```ini [baseten] remote_provider = baseten api_key = your-api-key remote_url = https://app.baseten.co ``` ## Push Options ```go result, err := client.Push(ctx, "./my-truss", "my-model", // Create a production deployment (default is development) truss.Publish(), // Promote to production immediately truss.Promote(), // Deploy to a specific environment truss.WithEnvironment("production"), // Set a custom deployment name truss.WithDeploymentName("v2.0-release"), // Assign to a team truss.WithTeam("ml-team"), // Include git commit info in deployment metadata truss.WithGitInfo(), // Keep previous production deployment's autoscaling truss.PreservePreviousProduction(), // Use existing environment's instance type truss.PreserveEnvInstanceType(), // Set backend deployment timeout truss.WithDeployTimeout(30 * time.Minute), // Allow downloading truss from Baseten UI truss.AllowTrussDownload(), ) ``` ## Working with Results ```go result, err := client.Push(ctx, trussDir, modelName) if err != nil { log.Fatal(err) } // Get deployment info fmt.Println("Model ID:", result.ModelID) fmt.Println("Version ID:", result.VersionID) fmt.Println("Predict URL:", result.PredictURL()) fmt.Println("Logs URL:", result.LogsURL(client.BaseURL())) fmt.Println("Is Draft:", result.IsDraft) // Wait for deployment to be ready err = result.WaitReady(ctx, 10*time.Minute) if err != nil { log.Fatal(err) } // Or check status manually status, err := result.Status(ctx) // status is one of: StatusBuilding, StatusDeploying, StatusActive, StatusFailed ``` ## Other Operations ```go // Get current user info user, err := client.WhoAmI(ctx) fmt.Println(user.Email, user.WorkspaceName) // List all models models, err := client.Models(ctx) // List models for a specific team models, err := client.Models(ctx, truss.WithTeamFilter("ml-team")) // List teams teams, err := client.Teams(ctx) // Validate a truss config without deploying result, err := client.Validate(ctx, "./my-truss") if !result.Success { fmt.Println("Validation errors:", result.Messages) } ``` ## Error Handling The SDK provides typed errors for different failure modes: ```go result, err := client.Push(ctx, trussDir, modelName) if err != nil { switch e := err.(type) { case *truss.AuthError: // Invalid or missing API key log.Fatal("Authentication failed:", e) case *truss.ValidationError: // Truss config validation failed fmt.Println("Errors:", e.Errors) fmt.Println("Warnings:", e.Warnings) case *truss.APIError: // Error response from Baseten API fmt.Printf("API error (code: %s): %s\n", e.Code, e.Message) case *truss.UploadError: // Failed to upload truss to S3 log.Fatal("Upload failed:", e) case *truss.ArchiveError: // Failed to create truss archive log.Fatal("Archive creation failed:", e) case *truss.ConfigError: // Problem with truss or SDK configuration log.Fatal("Config error:", e) default: log.Fatal(err) } } ``` ## .trussignore The SDK respects `.trussignore` files in your truss directory. This file uses gitignore-style patterns to exclude files from the upload. Default exclusions (applied even without a `.trussignore` file): - `.git` - `__pycache__` - `*.pyc`, `*.pyo` - `.DS_Store` - `.env`, `.venv`, `venv` - `node_modules` Example `.trussignore`: ``` # Exclude test files tests/ *_test.py # Exclude large data files *.csv *.parquet data/ # Exclude secrets secrets/ *.key ``` ## Development ### Running Tests ```bash # Run all unit tests go test -v ./... # Run tests with coverage go test -cover ./... ``` ### Running Integration Tests Integration tests push actual models to Baseten and require valid credentials in `~/.trussrc`. ```bash # Run integration tests (requires ~/.trussrc with valid API key) go test -tags=integration -v ./... ``` The integration tests will: - Authenticate using the "baseten" remote from `~/.trussrc` - Push a test truss to your workspace - Poll until the deployment reaches `MODEL_READY` status ## Requirements - Go 1.21 or later - A Baseten account and API key ## License MIT