⚾ Idiomatic Go library for the public MLB Stats API.
A typed Go client for statsapi.mlb.com. MLB does not publish an OpenAPI
specification, so this repo authors one and generates the underlying
client from it. Builds on years of community reverse engineering by
toddrob99/MLB-StatsAPI (Python) and BillPetti/baseballr (R); the
public surface in pkg/mlb hides the API's quirks behind idiomatic
helpers.
go get github.com/retr0h/mlb-sdk/pkg/mlb40+ endpoints (click to expand)
Run any example with go run examples/<name>.go. Roadmap for additional
endpoints lives in docs/roadmap.md.
| Feature | Description |
|---|---|
| OpenAPI-first | Hand-authored spec + generated client (oapi-codegen) |
| Idiomatic surface | time.Time, typed mlb.TeamID, helper methods |
| Hides API quirks | e.g. box.Team(mlb.LAD).DoublePlaysTurned() |
| Test-friendly | WithBaseURL injects an httptest.Server for fixtures |
This module exists because the MLB Stats API is undocumented and the most useful prior art is in Python and R:
See the package documentation on pkg.go.dev for API details.
See the Development guide for prerequisites, setup, and conventions. See the Contributing guide before submitting a PR.
| Project | Description |
|---|---|
| mlb-mcp | MCP server that exposes this SDK as tools for LLMs |
This package and its author are not affiliated with MLB or any MLB team. This module is a typed Go client for MLB's public Stats API. Use of MLB data is subject to the notice posted at http://gdx.mlb.com/components/copyright.txt.
The MIT License.