SDKs#

Antfly provides type-safe client libraries for Go, TypeScript, Python, and Rust. The Go, TypeScript, and Python SDKs are hand-written clients over code generated from the OpenAPI specification; the Rust SDK is generated from it end to end.

LanguagePackageRegistrySource
Gogithub.com/antflydb/antfly/go/pkg/sdkpkg.go.devGitHub
TypeScript@antfly/sdknpmGitHub
Pythonantfly-sdkPyPIGitHub
Rustantfly-sdkNot yet published; use a git dependencyGitHub

Embedded Lite Binding#

Antfly Lite embeds Antfly directly in an application process with a live .aflite database file. The first Lite binding above Zig and C is Go:

go get github.com/antflydb/antfly/go/pkg/antflylite

The Lite binding is separate from the network SDK. Use github.com/antflydb/antfly/go/pkg/sdk for a running Antfly service and github.com/antflydb/antfly/go/pkg/antflylite for embedded local databases.

See the Antfly Lite guide for CLI and Go embedded examples, plus backup, restore, and promotion between Lite and a running instance.

Installation#

go get github.com/antflydb/antfly/go/pkg/sdk

Authentication#

All three authentication methods are supported across SDKs: basic auth, API key, and token.

Basic Auth#

import (
	antfly "github.com/antflydb/antfly/go/pkg/sdk"
	"github.com/antflydb/antfly/go/pkg/sdk/oapi"
)

client, err := antfly.NewAntflyClientWithOptions(
	"http://127.0.0.1:8080",
	oapi.WithRequestEditorFn(antfly.WithBasicAuth("admin", "password")),
)

API Key#

client, err := antfly.NewAntflyClientWithOptions(
	"http://127.0.0.1:8080",
	oapi.WithRequestEditorFn(antfly.WithApiKey("key-id", "key-secret")),
)

Token#

client, err := antfly.NewAntflyClientWithOptions(
	"http://127.0.0.1:8080",
	oapi.WithRequestEditorFn(antfly.WithToken("your-token")),
)

Quick Start#

Insert Documents#

import (
	"context"
	"log"

	antfly "github.com/antflydb/antfly/go/pkg/sdk"
	"github.com/antflydb/antfly/go/pkg/sdk/oapi"
)

ctx := context.Background()
client, err := antfly.NewAntflyClientWithOptions(
	"http://127.0.0.1:8080",
	oapi.WithRequestEditorFn(antfly.WithBasicAuth("admin", "password")),
)
if err != nil {
	log.Fatal(err)
}

// Batch insert documents
result, err := client.Batch(ctx, "products", antfly.BatchRequest{
	Inserts: map[string]any{
		"prod:001": map[string]any{
			"name":  "Laptop",
			"price": 1299.99,
		},
		"prod:002": map[string]any{
			"name":  "Mouse",
			"price": 29.99,
		},
	},
})

Query#

import "github.com/antflydb/antfly/go/pkg/sdk/query"

fullText := query.NewQueryString("laptop")
results, err := client.Query(ctx, antfly.QueryRequest{
	Table:          "products",
	FullTextSearch: &fullText,
	Limit:          10,
})
if err != nil {
	log.Fatal(err)
}

for _, hit := range results.Responses[0].Hits.Hits {
	fmt.Printf("%s: %v\n", hit.ID, hit.Source)
}

Rust has no query sample. Its client is generated straight from the OpenAPI spec by progenitor, and the generated QueryRequest carries only table, fields, hierarchy, limit, and timeout_ms, so it cannot express full_text_search or semantic_search. Send search requests over HTTP directly until the generated request type covers them.

React Components#

For search UIs, @antfly/components is a React component library with search boxes, facets, result lists, and answer boxes. Add Search and AI Answers to Your Site builds a page with it; the React Antfly reference covers every component.

npm install @antfly/components @antfly/sdk