[go: nahoru, domu]

Skip to content

diverged/goalex

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

openalex-api

Warning: Early Stage Development

This project may be subject to:

  • Bugs
  • Bad Code
  • Breaking Changes
  • Abandonment

About

This is a (fledgling) Go library for OpenAlex.

OpenAlex is an index of hundreds of millions of interconnected scholarly papers, authors, institutions, and more. OpenAlex offers a robust, open, and free REST API to extract, aggregate, or search scholarly data.

This project aims to be an efficient yet powerful Go interface for the OpenAlex API, analogous to PyAlex.

The following features of OpenAlex are currently supported by this Go library:

  • Get single entities
  • Filter entities
  • Search entities
  • Group entities
  • Search filters
  • Select fields
  • Sample
  • Pagination
  • N-grams
  • Autocomplete endpoint
  • Authentication

Installation

To install the OpenAlex-API library, use the following command:

go get github.com/diverged/goalex

Usage

Below are some examples of how to use the OpenAlex-API library.

Get a Single Work by OpenAlex ID

package main

import (
    "fmt"
    "log"

    "github.com/diverged/goalex/pkg/api"
    "github.com/diverged/goalex/pkg/config"
)

func main() {
    client := api.NewClient(config.Config{
        Email: "your-email@example.com",
    })

    works := api.NewWorks(client)
    work, err := works.GetByOpenAlexID("W12345678")
    if err != nil {
        log.Fatalf("Error getting work: %v", err)
    }

    fmt.Printf("Work Title: %s\n", work.Title)
}

Filter Works by Publication Year

package main

import (
    "fmt"
    "log"

    "github.com/diverged/goalex/pkg/api"
    "github.com/diverged/goalex/pkg/config"
)

func main() {
    client := api.NewClient(config.Config{
        Email: "your-email@example.com",
    })

    works := api.NewWorks(client)
    filteredWorks, _, err := works.Filter(map[string]interface{}{
        "publication_year": 2020,
    }).Get()
    if err != nil {
        log.Fatalf("Error filtering works: %v", err)
    }

    for _, work := range filteredWorks {
        fmt.Printf("Work Title: %s\n", work.Title)
    }
}

License

This project is licensed under the MIT License. See the LICENSE file for details.