Openfda SDK

Openfda SDK

openFDA API client, generated from the OpenAPI spec.

This is an unofficial SDK for the openFDA public API, generated by Voxgig with @voxgig/sdkgen. It is not affiliated with, endorsed by, or sponsored by the upstream API provider.

TypeScript, Python, PHP, Golang, Ruby, Lua SDKs, a CLI, an interactive REPL, and an MCP server for AI agents — all generated from one OpenAPI spec by @voxgig/sdkgen.

Entities, not endpoints

This SDK exposes the API as a small set of semantic entities — Classification, Drug, Drugsfda, Enforcement, Event, Label, N510k, Ndc, Nsde, Pma, Problem, Shortage and Substance — that you call directly, instead of assembling URL paths and query strings. Entities are Capitalised to mark them as the primary surface, each with the operations they support (list):

const client = new OpenfdaSDK()
const items = await client.Classification().list()

Thinking in entities keeps the mental model small — for people and AI agents alike — rather than reasoning about raw HTTP routes and query parameters.

Packages

LanguagePackageInstall
TypeScript@voxgig-sdk/openfdapublish pending — install from git tag
Pythonvoxgig-sdk-openfdapublish pending — install from git tag
PHPvoxgig-sdk/openfdapublish pending — install from git tag
Golanggithub.com/voxgig-sdk/openfda-sdk/gogo get github.com/voxgig-sdk/openfda-sdk/go@latest
Rubyvoxgig-sdk-openfdapublish pending — install from git tag
Luavoxgig-sdk-openfdapublish pending — install from git tag

Quickstart

TypeScript

import { OpenfdaSDK } from '@voxgig-sdk/openfda'

const client = new OpenfdaSDK({
  apikey: process.env.OPENFDA_APIKEY,
})

// List all classifications (returns Classification[])
const classifications = await client.Classification().list()
for (const classification of classifications) {
  console.log(classification)
}

See the TypeScript README for the full guide.

Surfaces

SurfacePath
SDK (TypeScript, Python, PHP, Golang, Ruby, Lua)ts/ py/ php/ go/ rb/ lua/
CLIgo-cli/
MCP servergo-mcp/

Use it from an AI agent (MCP)

The generated MCP server exposes every operation in this SDK as an MCP tool that Claude, Cursor or Cline can call directly. Build and register it:

cd go-mcp && go build -o openfda-mcp .

Then add it to your agent’s MCP config (Claude Desktop, Cursor, etc.):

{
  "mcpServers": {
    "openfda": {
      "command": "/abs/path/to/openfda-mcp"
    }
  }
}

Entities

The API exposes 13 entities:

EntityDescriptionAPI path
ClassificationThe Classification entity (list)./device/classification.json
DrugThe Drug entity (list)./drug/event.json
DrugsfdaThe Drugsfda entity (list)./drug/drugsfda.json
EnforcementThe Enforcement entity (list)./device/enforcement.json
EventThe Event entity (list)./cosmetic/event.json
LabelThe Label entity (list)./drug/label.json
N510kThe N510k entity (list)./device/510k.json
NdcThe Ndc entity (list)./drug/ndc.json
NsdeThe Nsde entity (list)./other/nsde.json
PmaThe Pma entity (list)./device/pma.json
ProblemThe Problem entity (list)./tobacco/problem.json
ShortageThe Shortage entity (list)./drug/shortages.json
SubstanceThe Substance entity (list)./other/substance.json

The operations available across these entities are list — see each entity’s own list above for exactly which it supports.

Quickstart in other languages

Python

import os
from openfda_sdk import OpenfdaSDK

client = OpenfdaSDK({
    "apikey": os.environ.get("OPENFDA_APIKEY"),
})

# List all classifications (returns a list, raises on error)
classifications = client.Classification().list()
for classification in classifications:
    print(classification)

PHP

<?php
require_once 'openfda_sdk.php';

$client = new OpenfdaSDK([
    "apikey" => getenv("OPENFDA_APIKEY"),
]);

// List all classifications (returns an array; throws on error)
$classifications = $client->Classification()->list();
print_r($classifications);

Golang

import sdk "github.com/voxgig-sdk/openfda-sdk/go"

client := sdk.NewOpenfdaSDK(map[string]any{
    "apikey": os.Getenv("OPENFDA_APIKEY"),
})

// List all classifications
classifications, err := client.Classification(nil).List(nil, nil)
fmt.Println(classifications)

Ruby

require_relative "Openfda_sdk"

client = OpenfdaSDK.new({
  "apikey" => ENV["OPENFDA_APIKEY"],
})

# List all classifications (returns an Array; raises on error)
classifications = client.Classification.list
puts classifications

Lua

local sdk = require("openfda_sdk")

local client = sdk.new({
  apikey = os.getenv("OPENFDA_APIKEY"),
})

-- List all classifications
local classifications, err = client:Classification():list()
print(classifications)

Unit testing in offline mode

Every SDK ships a test mode that swaps the HTTP transport for an in-memory mock, so unit tests run offline.

TypeScript

const client = OpenfdaSDK.test()
const classification = await client.Classification().list()
// classification is a bare Classification populated with mock data
console.log(classification)

Python

client = OpenfdaSDK.test()
classification = client.Classification().list()
print(classification)

PHP

// Seed fixture data so offline calls resolve without a live server.
$client = OpenfdaSDK::test([
    "entity" => ["classification" => ["test01" => []]],
]);
$classification = $client->Classification()->list();

Golang

client := sdk.Test()
result, err := client.Classification(nil).List(
    nil, nil,
)

Ruby

# Seed fixture data so offline calls resolve without a live server.
client = OpenfdaSDK.test({
  "entity" => { "classification" => { "test01" => {} } },
})
classification = client.Classification.list()

Lua

local client = sdk.test()
local result, err = client:Classification():list()

Direct and prepare

For endpoints the entity model doesn’t cover, use the low-level methods:

  • direct(fetchargs) — build and send an HTTP request in one step.
  • prepare(fetchargs) — build the request without sending it.

Both accept a map with path, method, params, query, headers, and body. See the How-to guides below.

How-to guides

Make a direct API call

When the entity interface does not cover an endpoint, use direct:

TypeScript:

const result = await client.direct({
  path: '/api/resource/{id}',
  method: 'GET',
  params: { id: 'example' },
})
if (result instanceof Error) {
  throw result
}
console.log(result.data)

Python:

result = client.direct({
    "path": "/api/resource/{id}",
    "method": "GET",
    "params": {"id": "example"},
})

PHP:

$result = $client->direct([
    "path" => "/api/resource/{id}",
    "method" => "GET",
    "params" => ["id" => "example"],
]);

Go:

result, err := client.Direct(map[string]any{
    "path":   "/api/resource/{id}",
    "method": "GET",
    "params": map[string]any{"id": "example"},
})

Ruby:

result = client.direct({
  "path" => "/api/resource/{id}",
  "method" => "GET",
  "params" => { "id" => "example" },
})

Lua:

local result, err = client:direct({
  path = "/api/resource/{id}",
  method = "GET",
  params = { id = "example" },
})

Advanced

Everyday use only needs the sections above. This explains the internals behind every call — relevant when writing custom features.

Every SDK call runs the same five-stage pipeline:

  1. Point — resolve the API endpoint from the operation definition.
  2. Spec — build the HTTP specification (URL, method, headers, body).
  3. Request — send the HTTP request.
  4. Response — receive and parse the response.
  5. Result — extract the result data for the caller.

A feature hook fires at each stage (e.g. PrePoint, PreSpec, PreRequest), so features can inspect or modify the pipeline without forking the SDK.

Features

FeaturePurpose
TestFeatureIn-memory mock transport for testing without a live server

Pass custom features via the extend option at construction time.

Per-language documentation

Upstream API

This SDK is generated from the upstream OpenAPI specification. It is an unofficial client and is not affiliated with the API provider.

Security

Please report security issues to security@voxgig.com. See SECURITY.md. Do not open public issues for suspected vulnerabilities.


Generated from the openFDA API OpenAPI spec by @voxgig/sdkgen.

Get the Voxgig dispatch

Short notes on building SDKs, CLIs, REPLs, and MCPs for API-first teams, plus the occasional Fireside episode pick.

By signing up you agree to our Terms and Conditions.