anytype

package module
v0.53.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 10, 2026 License: Apache-2.0 Imports: 4 Imported by: 1

README

Anytype-Go SDK

Go Report Card GoDoc

Go SDK for the Anytype local API. Compatible with API version 2025-11-08.

Installation

go get github.com/epheo/anytype-go
import (
    "github.com/epheo/anytype-go"
    _ "github.com/epheo/anytype-go/client"
)

Authentication

client := anytype.NewClient(
    anytype.WithBaseURL("http://localhost:31009"),
)

// Initiate challenge — Anytype app will display a verification code
auth, _ := client.Auth().CreateChallenge(ctx, "MyApp")

// User enters the code
var code string
fmt.Scanln(&code)

// Exchange for API key
token, _ := client.Auth().CreateApiKey(ctx, auth.ChallengeID, code)

// Create authenticated client
client = anytype.NewClient(
    anytype.WithBaseURL("http://localhost:31009"),
    anytype.WithAppKey(token.ApiKey),
)

Usage

The SDK uses a fluent interface that mirrors the resource hierarchy:

// Spaces
spaces, _ := client.Spaces().List(ctx)
space, _ := client.Space(spaceID).Get(ctx)

// Objects
objects, _ := client.Space(spaceID).Objects().List(ctx)
object, _ := client.Space(spaceID).Object(objectID).Get(ctx)
markdown, _ := client.Space(spaceID).Object(objectID).Get(ctx, anytype.WithFormat("md"))

// Types and templates
types, _ := client.Space(spaceID).Types().List(ctx)
templates, _ := client.Space(spaceID).Type(typeKey).Templates().List(ctx)

// Lists and views
views, _ := client.Space(spaceID).List(listID).Views().List(ctx)
_ = client.Space(spaceID).List(listID).Objects().Add(ctx, []string{objectID})

// Properties and tags
props, _ := client.Space(spaceID).Properties().List(ctx)
tags, _ := client.Space(spaceID).Property(propID).Tags().List(ctx)

// Members
members, _ := client.Space(spaceID).Members().List(ctx)

// Search (within a space or globally)
results, _ := client.Space(spaceID).Search(ctx, anytype.SearchRequest{
    Query: "meeting notes",
    Types: []string{"page"},
    Sort:  &anytype.SortOptions{
        Property:  anytype.SortPropertyLastModifiedDate,
        Direction: anytype.SortDirectionDesc,
    },
})
globalResults, _ := client.Search().Search(ctx, anytype.SearchRequest{Query: "notes"})

See examples/usage_examples.go for complete working examples and GoDoc for the full API reference.

Testing SDK coverage

go test -v ./tests_api_coverage/... # API coverage tests

License

Apache License 2.0 - see LICENSE.

Documentation

Overview

Package anytype provides a Go SDK for interacting with the Anytype API.

Index

Constants

View Source
const (
	MemberRoleViewer       MemberRole = "viewer"
	MemberRoleEditor       MemberRole = "editor"
	MemberRoleOwner        MemberRole = "owner"
	MemberRoleNoPermission MemberRole = "no_permission"

	MemberStatusJoining  MemberStatus = "joining"
	MemberStatusActive   MemberStatus = "active"
	MemberStatusRemoved  MemberStatus = "removed"
	MemberStatusDeclined MemberStatus = "declined"
	MemberStatusRemoving MemberStatus = "removing"
	MemberStatusCanceled MemberStatus = "canceled"
)
View Source
const (
	SortPropertyCreatedDate      SortProperty = "created_date"
	SortPropertyLastModifiedDate SortProperty = "last_modified_date"
	SortPropertyLastOpenedDate   SortProperty = "last_opened_date"
	SortPropertyName             SortProperty = "name"

	SortDirectionAsc  SortDirection = "asc"
	SortDirectionDesc SortDirection = "desc"
)
View Source
const (
	// Follows AnyType Versioning
	Version    = "0.53.1"
	APIVersion = "2025-11-08"
)

Variables

View Source
var ErrTypeNotFound = errors.New("type not found")

Functions

func RegisterClientConstructor

func RegisterClientConstructor(constructor clientConstructor)

Types

type AuthClient

type AuthClient interface {
	CreateChallenge(ctx context.Context, appName string) (*CreateChallengeResponse, error)
	CreateApiKey(ctx context.Context, challengeID string, code string) (*CreateApiKeyResponse, error)
}

type Client

type Client interface {
	Auth() AuthClient
	Spaces() SpaceClient
	Space(spaceID string) SpaceContext
	Search() SearchClient
}

func NewClient

func NewClient(opts ...ClientOption) Client

type ClientOption

type ClientOption func(*ClientOptions)

func WithAppKey

func WithAppKey(appKey string) ClientOption

func WithBaseURL

func WithBaseURL(url string) ClientOption

type ClientOptions

type ClientOptions struct {
	BaseURL string
	AppKey  string
}

type CreateApiKeyResponse added in v0.4.0

type CreateApiKeyResponse struct {
	ApiKey string `json:"api_key"`
}

type CreateChallengeResponse added in v0.4.0

type CreateChallengeResponse struct {
	ChallengeID string `json:"challenge_id"`
}

type CreateObjectRequest

type CreateObjectRequest struct {
	TypeKey    string                  `json:"type_key"`
	Name       string                  `json:"name,omitempty"`
	Body       string                  `json:"body,omitempty"`
	Icon       *Icon                   `json:"icon,omitempty"`
	TemplateID string                  `json:"template_id,omitempty"`
	Properties []PropertyLinkWithValue `json:"properties,omitempty"`
}

type CreatePropertyRequest added in v0.53.1

type CreatePropertyRequest struct {
	Name   string             `json:"name"`
	Format string             `json:"format"`
	Key    string             `json:"key,omitempty"`
	Tags   []CreateTagRequest `json:"tags,omitempty"`
}

type CreateSpaceRequest

type CreateSpaceRequest struct {
	Name        string `json:"name"`
	Description string `json:"description,omitempty"`
}

type CreateTagRequest added in v0.53.1

type CreateTagRequest struct {
	Name  string `json:"name"`
	Color string `json:"color"`
	Key   string `json:"key,omitempty"`
}

type CreateTypeRequest added in v0.3.4

type CreateTypeRequest struct {
	Key        string               `json:"key,omitempty"`
	Name       string               `json:"name"`
	Icon       *Icon                `json:"icon,omitempty"`
	Layout     string               `json:"layout"`
	PluralName string               `json:"plural_name"`
	Properties []PropertyDefinition `json:"properties,omitempty"`
}

type FilterCondition added in v0.53.1

type FilterCondition string
const (
	FilterConditionEq     FilterCondition = "eq"
	FilterConditionNe     FilterCondition = "ne"
	FilterConditionIn     FilterCondition = "in"
	FilterConditionNin    FilterCondition = "nin"
	FilterConditionEmpty  FilterCondition = "empty"
	FilterConditionNEmpty FilterCondition = "nempty"

	FilterConditionContains  FilterCondition = "contains"
	FilterConditionNContains FilterCondition = "ncontains"

	FilterConditionGt  FilterCondition = "gt"
	FilterConditionLt  FilterCondition = "lt"
	FilterConditionGte FilterCondition = "gte"
	FilterConditionLte FilterCondition = "lte"

	FilterConditionAll FilterCondition = "all"
)

type FilterExpression added in v0.53.1

type FilterExpression struct {
	Operator   FilterOperator     `json:"operator,omitempty"`
	Filters    []FilterExpression `json:"filters,omitempty"`
	Conditions []FilterItem       `json:"conditions,omitempty"`
}

type FilterFormat added in v0.53.1

type FilterFormat string

FilterFormat determines which JSON field name is used when serializing filter values. The API expects format-specific field names (e.g. "text", "number", "checkbox") rather than generic "value" fields.

const (
	FilterFormatText        FilterFormat = "text"
	FilterFormatNumber      FilterFormat = "number"
	FilterFormatSelect      FilterFormat = "select"
	FilterFormatMultiSelect FilterFormat = "multi_select"
	FilterFormatDate        FilterFormat = "date"
	FilterFormatCheckbox    FilterFormat = "checkbox"
	FilterFormatFiles       FilterFormat = "files"
	FilterFormatURL         FilterFormat = "url"
	FilterFormatEmail       FilterFormat = "email"
	FilterFormatPhone       FilterFormat = "phone"
	FilterFormatObjects     FilterFormat = "objects"
)

type FilterItem added in v0.53.1

type FilterItem struct {
	Key       string          `json:"-"`
	Format    FilterFormat    `json:"-"`
	Condition FilterCondition `json:"-"`
	Value     interface{}     `json:"-"`
}

FilterItem represents a single filter condition. Set Format to indicate which type of filter value is being used (e.g. FilterFormatText, FilterFormatCheckbox). For empty/nempty conditions, Format and Value can be omitted.

func CheckboxFilter added in v0.53.1

func CheckboxFilter(key string, condition FilterCondition, checked bool) FilterItem

func DateFilter added in v0.53.1

func DateFilter(key string, condition FilterCondition, date string) FilterItem

func EmailFilter added in v0.53.1

func EmailFilter(key string, condition FilterCondition, email string) FilterItem

func EmptyFilter added in v0.53.1

func EmptyFilter(key string, condition FilterCondition) FilterItem

func FilesFilter added in v0.53.1

func FilesFilter(key string, condition FilterCondition, fileIDs []string) FilterItem

func MultiSelectFilter added in v0.53.1

func MultiSelectFilter(key string, condition FilterCondition, tagIDs []string) FilterItem

func NumberFilter added in v0.53.1

func NumberFilter(key string, condition FilterCondition, number float64) FilterItem

func ObjectsFilter added in v0.53.1

func ObjectsFilter(key string, condition FilterCondition, objectIDs []string) FilterItem

func PhoneFilter added in v0.53.1

func PhoneFilter(key string, condition FilterCondition, phone string) FilterItem

func SelectFilter added in v0.53.1

func SelectFilter(key string, condition FilterCondition, tagID string) FilterItem

func TextFilter added in v0.53.1

func TextFilter(key string, condition FilterCondition, text string) FilterItem

func URLFilter added in v0.53.1

func URLFilter(key string, condition FilterCondition, url string) FilterItem

func (FilterItem) MarshalJSON added in v0.53.1

func (f FilterItem) MarshalJSON() ([]byte, error)

func (*FilterItem) UnmarshalJSON added in v0.53.1

func (f *FilterItem) UnmarshalJSON(data []byte) error

type FilterOperator added in v0.53.1

type FilterOperator string
const (
	FilterOperatorAnd FilterOperator = "and"
	FilterOperatorOr  FilterOperator = "or"
)

type GetOption added in v0.53.1

type GetOption func(*GetOptions)

func WithFormat added in v0.53.1

func WithFormat(format string) GetOption

type GetOptions added in v0.53.1

type GetOptions struct {
	Format string
}

func ApplyGetOptions added in v0.53.1

func ApplyGetOptions(opts ...GetOption) GetOptions

type Icon

type Icon struct {
	Format IconFormat `json:"format,omitempty"`
	Emoji  string     `json:"emoji,omitempty"`
	File   string     `json:"file,omitempty"`
	Name   string     `json:"name,omitempty"`
	Color  string     `json:"color,omitempty"`
}

type IconFormat

type IconFormat string
const (
	IconFormatEmoji IconFormat = "emoji"
	IconFormatFile  IconFormat = "file"
	IconFormatIcon  IconFormat = "icon"
)

type ListContext

type ListContext interface {
	Views() ViewClient
	View(viewID string) ViewContext
	Objects() ObjectListClient
	Object(objectID string) ObjectListContext
}

type ListFilter

type ListFilter struct {
	ID          string `json:"id"`
	PropertyKey string `json:"property_key"`
	Format      string `json:"format"`
	Condition   string `json:"condition"`
	Value       string `json:"value"`
}

type ListOption added in v0.53.1

type ListOption func(*ListOptions)

func WithLimit added in v0.53.1

func WithLimit(limit int) ListOption

func WithOffset added in v0.53.1

func WithOffset(offset int) ListOption

type ListOptions added in v0.53.1

type ListOptions struct {
	Limit  int
	Offset int
}

func ApplyListOptions added in v0.53.1

func ApplyListOptions(opts ...ListOption) ListOptions

type ListSort

type ListSort struct {
	ID          string `json:"id"`
	PropertyKey string `json:"property_key"`
	Format      string `json:"format"`
	SortType    string `json:"sort_type"`
}

type ListView

type ListView struct {
	ID      string       `json:"id"`
	Name    string       `json:"name"`
	Layout  string       `json:"layout"`
	Filters []ListFilter `json:"filters,omitempty"`
	Sorts   []ListSort   `json:"sorts,omitempty"`
}

type Member

type Member struct {
	ID         string       `json:"id"`
	Object     string       `json:"object"`
	Name       string       `json:"name"`
	GlobalName string       `json:"global_name"`
	Identity   string       `json:"identity"`
	Role       MemberRole   `json:"role"`
	Status     MemberStatus `json:"status"`
	Icon       *Icon        `json:"icon,omitempty"`
}

type MemberClient

type MemberClient interface {
	List(ctx context.Context) (*MemberListResponse, error)
}

type MemberContext

type MemberContext interface {
	Get(ctx context.Context) (*MemberResponse, error)
}

type MemberListResponse

type MemberListResponse struct {
	Data       []Member   `json:"data"`
	Pagination Pagination `json:"pagination"`
}

type MemberResponse

type MemberResponse struct {
	Member Member `json:"member"`
}

type MemberRole

type MemberRole string

type MemberStatus

type MemberStatus string

type Object

type Object struct {
	ID         string     `json:"id"`
	Object     string     `json:"object"`
	Name       string     `json:"name"`
	SpaceID    string     `json:"space_id"`
	Layout     string     `json:"layout"`
	Archived   bool       `json:"archived"`
	Icon       *Icon      `json:"icon,omitempty"`
	Snippet    string     `json:"snippet"`
	Properties []Property `json:"properties"`
	Type       *Type      `json:"type,omitempty"`
	Markdown   string     `json:"markdown,omitempty"`
}

type ObjectClient

type ObjectClient interface {
	List(ctx context.Context, opts ...ListOption) ([]Object, error)
	Create(ctx context.Context, request CreateObjectRequest) (*ObjectResponse, error)
}

type ObjectContext

type ObjectContext interface {
	Get(ctx context.Context, opts ...GetOption) (*ObjectResponse, error)
	Update(ctx context.Context, request UpdateObjectRequest) (*ObjectResponse, error)
	Delete(ctx context.Context) (*ObjectResponse, error)
}

type ObjectListClient

type ObjectListClient interface {
	Add(ctx context.Context, objectIDs []string) error
}

type ObjectListContext

type ObjectListContext interface {
	Remove(ctx context.Context) error
}

type ObjectListResponse

type ObjectListResponse struct {
	Data       []Object   `json:"data"`
	Pagination Pagination `json:"pagination"`
}

type ObjectResponse

type ObjectResponse struct {
	Object *Object `json:"object"`
}

type ObjectViewClient

type ObjectViewClient interface {
	List(ctx context.Context) (*ObjectListResponse, error)
}

type Pagination added in v0.53.1

type Pagination struct {
	Total   int  `json:"total"`
	Limit   int  `json:"limit"`
	Offset  int  `json:"offset"`
	HasMore bool `json:"has_more"`
}

type Property

type Property struct {
	ID          string   `json:"id,omitempty"`
	Format      string   `json:"format,omitempty"`
	Key         string   `json:"key,omitempty"`
	Name        string   `json:"name,omitempty"`
	Object      string   `json:"object,omitempty"`
	Text        string   `json:"text,omitempty"`
	Number      float64  `json:"number,omitempty"`
	Checkbox    bool     `json:"checkbox,omitempty"`
	Date        string   `json:"date,omitempty"`
	URL         string   `json:"url,omitempty"`
	Email       string   `json:"email,omitempty"`
	Phone       string   `json:"phone,omitempty"`
	Files       []string `json:"files,omitempty"`
	Select      *Tag     `json:"select,omitempty"`
	MultiSelect []Tag    `json:"multi_select,omitempty"`
	Objects     []string `json:"objects,omitempty"`
}

type PropertyContext added in v0.53.1

type PropertyContext interface {
	Get(ctx context.Context) (*PropertyResponse, error)
	Update(ctx context.Context, request UpdatePropertyRequest) (*PropertyResponse, error)
	Delete(ctx context.Context) (*PropertyResponse, error)
	Tags() TagClient
	Tag(tagID string) TagContext
}

type PropertyDefinition

type PropertyDefinition struct {
	Key    string `json:"key"`
	Name   string `json:"name"`
	Format string `json:"format"`
}

type PropertyLinkWithValue added in v0.53.1

type PropertyLinkWithValue struct {
	Key         string   `json:"key"`
	Text        *string  `json:"text,omitempty"`
	Number      *float64 `json:"number,omitempty"`
	Checkbox    *bool    `json:"checkbox,omitempty"`
	Date        *string  `json:"date,omitempty"`
	URL         *string  `json:"url,omitempty"`
	Email       *string  `json:"email,omitempty"`
	Phone       *string  `json:"phone,omitempty"`
	Files       []string `json:"files,omitempty"`
	Select      *string  `json:"select,omitempty"`
	MultiSelect []string `json:"multi_select,omitempty"`
	Objects     []string `json:"objects,omitempty"`
}

type PropertyResponse added in v0.53.1

type PropertyResponse struct {
	Property Property `json:"property"`
}

type SearchClient

type SearchClient interface {
	Search(ctx context.Context, request SearchRequest) (*SearchResponse, error)
}

type SearchRequest

type SearchRequest struct {
	Query   string            `json:"query"`
	Types   []string          `json:"types,omitempty"`
	Sort    *SortOptions      `json:"sort,omitempty"`
	Filters *FilterExpression `json:"filters,omitempty"`
}

type SearchResponse

type SearchResponse struct {
	Data       []Object   `json:"data"`
	Pagination Pagination `json:"pagination"`
}

type SortDirection

type SortDirection string

type SortOptions

type SortOptions struct {
	Property  SortProperty  `json:"property_key"`
	Direction SortDirection `json:"direction"`
}

type SortProperty

type SortProperty string

type Space

type Space struct {
	ID          string `json:"id"`
	Name        string `json:"name"`
	Description string `json:"description,omitempty"`
	Icon        *Icon  `json:"icon,omitempty"`
	NetworkID   string `json:"network_id,omitempty"`
	GatewayURL  string `json:"gateway_url,omitempty"`
	Object      string `json:"object"`
}

type SpaceClient

type SpaceClient interface {
	List(ctx context.Context) (*SpaceListResponse, error)
	Create(ctx context.Context, request CreateSpaceRequest) (*SpaceResponse, error)
}

type SpaceContext

type SpaceContext interface {
	Get(ctx context.Context) (*SpaceResponse, error)
	Update(ctx context.Context, request UpdateSpaceRequest) (*SpaceResponse, error)
	Objects() ObjectClient
	Object(objectID string) ObjectContext
	Types() TypeClient
	Type(typeID string) TypeContext
	Search(ctx context.Context, request SearchRequest) (*SearchResponse, error)
	List(listID string) ListContext
	Members() MemberClient
	Member(memberID string) MemberContext
	Properties() SpacePropertyClient
	Property(propertyID string) PropertyContext
}

type SpaceListResponse

type SpaceListResponse struct {
	Data       []Space    `json:"data"`
	Pagination Pagination `json:"pagination"`
}

type SpacePropertyClient added in v0.53.1

type SpacePropertyClient interface {
	List(ctx context.Context) ([]Property, error)
	Create(ctx context.Context, request CreatePropertyRequest) (*PropertyResponse, error)
}

type SpaceResponse

type SpaceResponse struct {
	Space Space `json:"space"`
}

type Tag

type Tag struct {
	ID     string `json:"id,omitempty"`
	Key    string `json:"key,omitempty"`
	Name   string `json:"name,omitempty"`
	Color  string `json:"color,omitempty"`
	Object string `json:"object,omitempty"`
}

type TagClient added in v0.53.1

type TagClient interface {
	List(ctx context.Context) ([]Tag, error)
	Create(ctx context.Context, request CreateTagRequest) (*TagResponse, error)
}

type TagContext added in v0.53.1

type TagContext interface {
	Get(ctx context.Context) (*TagResponse, error)
	Update(ctx context.Context, request UpdateTagRequest) (*TagResponse, error)
	Delete(ctx context.Context) (*TagResponse, error)
}

type TagResponse added in v0.53.1

type TagResponse struct {
	Tag Tag `json:"tag"`
}

type TemplateClient

type TemplateClient interface {
	List(ctx context.Context) ([]Object, error)
}

type TemplateContext

type TemplateContext interface {
	Get(ctx context.Context) (*TemplateResponse, error)
}

type TemplateResponse

type TemplateResponse struct {
	Template Object `json:"template"`
}

type Type

type Type struct {
	ID         string     `json:"id"`
	Key        string     `json:"key"`
	Name       string     `json:"name"`
	Object     string     `json:"object"`
	Icon       *Icon      `json:"icon,omitempty"`
	Layout     string     `json:"layout"`
	Archived   bool       `json:"archived"`
	PluralName string     `json:"plural_name,omitempty"`
	Properties []Property `json:"properties,omitempty"`
}

type TypeClient

type TypeClient interface {
	List(ctx context.Context) ([]Type, error)
	Get(ctx context.Context, typeKey string) (*Type, error)
	GetKeyByName(ctx context.Context, name string) (string, error)
	Create(ctx context.Context, request CreateTypeRequest) (*TypeResponse, error)
}

type TypeContext

type TypeContext interface {
	Get(ctx context.Context) (*TypeResponse, error)
	Update(ctx context.Context, request UpdateTypeRequest) (*TypeResponse, error)
	Delete(ctx context.Context) (*TypeResponse, error)
	Templates() TemplateClient
	Template(templateID string) TemplateContext
}

type TypeResponse

type TypeResponse struct {
	Type Type `json:"type"`
}

type UpdateObjectRequest

type UpdateObjectRequest struct {
	Name       string                  `json:"name,omitempty"`
	Markdown   string                  `json:"markdown,omitempty"`
	Icon       *Icon                   `json:"icon,omitempty"`
	TypeKey    string                  `json:"type_key,omitempty"`
	Properties []PropertyLinkWithValue `json:"properties,omitempty"`
}

type UpdatePropertyRequest added in v0.53.1

type UpdatePropertyRequest struct {
	Name string `json:"name"`
	Key  string `json:"key,omitempty"`
}

type UpdateSpaceRequest

type UpdateSpaceRequest struct {
	Name        *string `json:"name,omitempty"`
	Description *string `json:"description,omitempty"`
}

type UpdateTagRequest added in v0.53.1

type UpdateTagRequest struct {
	Name  string `json:"name,omitempty"`
	Color string `json:"color,omitempty"`
	Key   string `json:"key,omitempty"`
}

type UpdateTypeRequest added in v0.53.1

type UpdateTypeRequest struct {
	Key        string               `json:"key,omitempty"`
	Name       string               `json:"name,omitempty"`
	Icon       *Icon                `json:"icon,omitempty"`
	Layout     string               `json:"layout,omitempty"`
	PluralName string               `json:"plural_name,omitempty"`
	Properties []PropertyDefinition `json:"properties,omitempty"`
}

type VersionInfo

type VersionInfo struct {
	Version    string `json:"version"`
	APIVersion string `json:"api_version"`
}

func GetVersionInfo

func GetVersionInfo() VersionInfo

type ViewClient

type ViewClient interface {
	List(ctx context.Context) (*ViewListResponse, error)
}

type ViewContext

type ViewContext interface {
	Objects() ObjectViewClient
}

type ViewListResponse

type ViewListResponse struct {
	Data       []ListView `json:"data"`
	Pagination Pagination `json:"pagination"`
}

Directories

Path Synopsis
Package client implements the client interfaces defined in the anytype package
Package client implements the client interfaces defined in the anytype package
Package middleware provides HTTP middleware components for the anytype client
Package middleware provides HTTP middleware components for the anytype client

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL