openalex

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package openalex is the library behind the openalex command line: the HTTP client, request shaping, and the typed data models for openalex.

The Client here is the spine every command shares. It sets a real User-Agent, paces requests so a busy session stays polite, and retries the transient failures (429 and 5xx) that any public site throws under load.

Index

Constants

View Source
const BaseURL = "https://" + Host

BaseURL is the root every request is built from.

View Source
const DefaultUserAgent = "openalex-cli/dev (https://github.com/tamnd/openalex-cli; mailto:bot@example.com)"

DefaultUserAgent identifies the client to OpenAlex. The mailto: hint opts into the polite pool for higher rate limits.

View Source
const Host = "api.openalex.org"

Host is the site this client talks to.

Variables

This section is empty.

Functions

This section is empty.

Types

type Author

type Author struct {
	Rank         int    `json:"rank"`
	ID           string `json:"id"` // OpenAlex ID e.g. A27320202
	Name         string `json:"name"`
	WorksCount   int    `json:"works_count"`
	CitedByCount int    `json:"cited_by_count"`
	HIndex       int    `json:"h_index"`     // from summary_stats.h_index
	Affiliation  string `json:"affiliation"` // last institution name
}

Author is an individual researcher with career statistics.

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client talks to OpenAlex over HTTP.

func NewClient

func NewClient(cfg Config) *Client

NewClient returns a Client with the given config.

func (*Client) GetPage

func (c *Client) GetPage(ctx context.Context, p string) (*Page, error)

GetPage fetches one page by its path.

func (c *Client) PageLinks(ctx context.Context, p string, limit int) ([]*Page, error)

PageLinks is kept for the kit domain driver.

func (*Client) SearchAuthors

func (c *Client) SearchAuthors(ctx context.Context, query string, limit int) ([]Author, error)

SearchAuthors queries the OpenAlex /authors endpoint and returns up to limit results.

func (*Client) SearchWorks

func (c *Client) SearchWorks(ctx context.Context, query string, limit int) ([]Work, error)

SearchWorks queries the OpenAlex /works endpoint and returns up to limit results.

type Config

type Config struct {
	BaseURL   string
	UserAgent string
	Rate      time.Duration
	Timeout   time.Duration
	Retries   int
}

Config holds all tunables for the client.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns a Config with sensible defaults for the OpenAlex API.

type Domain

type Domain struct{}

Domain is the openalex driver. It carries no state; the per-run client is built by the factory Register hands kit.

func (Domain) Classify

func (Domain) Classify(input string) (uriType, id string, err error)

Classify turns any accepted input into the canonical (type, id).

func (Domain) Info

func (Domain) Info() kit.DomainInfo

Info describes the scheme, the hostnames a pasted link is matched against, and the identity reused for the binary's help and version.

func (Domain) Locate

func (Domain) Locate(uriType, id string) (string, error)

Locate is the inverse: the live https URL for a (type, id).

func (Domain) Register

func (Domain) Register(app *kit.App)

Register installs the client factory and every operation onto app.

type Page

type Page struct {
	ID    string `json:"id" kit:"id"`
	URL   string `json:"url"`
	Title string `json:"title,omitempty"`
	Body  string `json:"body,omitempty" kit:"body"`
}

Page is used by the kit domain driver as the URI-addressable resource.

type Work

type Work struct {
	Rank         int      `json:"rank"`
	ID           string   `json:"id"` // OpenAlex ID e.g. W2741809807
	DOI          string   `json:"doi"`
	Title        string   `json:"title"`
	Year         int      `json:"year"`
	Type         string   `json:"type"` // article, preprint, book, etc.
	OpenAccess   bool     `json:"open_access"`
	CitedByCount int      `json:"cited_by_count"`
	Authors      []string `json:"authors"`       // first 3 author display names
	PrimaryVenue string   `json:"primary_venue"` // journal or source name
	URL          string   `json:"url"`           // doi URL or landing page
}

Work is a single scholarly work (paper, preprint, book, dataset, etc.).

Jump to

Keyboard shortcuts

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