npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

connectedpapers-js

v0.1.5

Published

The official client for the connected papers API

Downloads

13

Readme

connectedpapers-js

The JS client for the connected papers API.

Installation

For npm:

npm install connectedpapers-js

For yarn:

yarn add connectedpapers-js

Usage

import { ConnectedPapersClient } from 'connectedpapers-js';

const DEEPFRUITS_PAPER_ID = "9397e7acd062245d37350f5c05faf56e9cfae0d6"

const client = new ConnectedPapersClient({access_token: "TEST_TOKEN"});
client.getGraph({paper_id: DEEPFRUITS_PAPER_ID, fresh_only: true}).then((paper) => {
  console.log(paper);
});
client.getRemainingUsages().then((remainingUses) => {
  console.log(`Remaining uses: ${remainingUses}`);
});
client.getFreeAccessPapers().then((freeAccessPapers) => {
  console.log(`Free access papers: ${freeAccessPapers}`);
});

API

The following async functions are part of the connected papers API:

  • getPaper({paper_id: string, fresh_only: boolean}): Returns the paper with the given ID. If fresh_only is true, then if the graph is over 30 days old, the call will wait for a rebuild.
  • getRemainingUsages(): Returns the number of remaining usages for the current API key.
  • getFreeAccessPapers(): Returns the number of free access papers for the current API key.

Free access papers

If you've already accessed a paper's graph within the past 30 days, any additional access to the same graph during this period won't be counted against your usage limit. Such repeated access is considered "free," and the paper in question is referred to as a "free access paper."

Supplying an API key

There are two ways to supply an API key to the client:

  • Set the CONNECTED_PAPERS_API_KEY environment variable.
export CONNECTED_PAPERS_API_KEY="<your api key>"

Then create the client without any arguments:

const client = new ConnectedPapersClient();
  • Pass the API key as an argument to the constructor:
const client = new ConnectedPapersClient({access_token: "<your api key>"});

Getting an API key

To get an early-access API key, contact us at [email protected].

You can use the API key TEST_TOKEN to access the graph of the paper with ID 9397e7acd062245d37350f5c05faf56e9cfae0d6 for testing purposes.

Paper IDs

We use ShaIDs by Semantic Scholar as paper IDs. You can find the ShaID of a paper by going to its Semantic Scholar page and copying the ID from the URL. For example, the ShaID of the paper DeepFruits: A Fruit Detection System Using Deep Neural Networks is 9397e7acd062245d37350f5c05faf56e9cfae0d6.

Async iterator access

The client also supports async iterator access to the API. This is useful for tracking the progress of graph builds and getting existing as well as rebuilt papers.

Calling the getGraphAsyncIterator returns an async iterator that yields the GraphResponse type:

export enum GraphResponseStatuses {
  BAD_ID = 'BAD_ID',
  ERROR = 'ERROR',
  NOT_IN_DB = 'NOT_IN_DB',
  OLD_GRAPH = 'OLD_GRAPH',
  FRESH_GRAPH = 'FRESH_GRAPH',
  IN_PROGRESS = 'IN_PROGRESS',
  QUEUED = 'QUEUED',
  BAD_TOKEN = 'BAD_TOKEN',
  BAD_REQUEST = 'BAD_REQUEST',
  OUT_OF_REQUESTS = 'OUT_OF_REQUESTS',
}

export type GraphResponse = {
  status: GraphResponseStatuses;
  graph_json?: Graph;
  progress?: number;
};

Once the status is one of BAD_ID, ERROR, NOT_IN_DB, BAD_TOKEN, BAD_REQUEST, OUT_OF_REQUESTS, the iterator will stop yielding values.

Signature:

class ConnectedPapersClient {
  // ...
  public async* getGraphAsyncIterator(args: {
    paper_id: PaperId;
    fresh_only?: boolean;
    loop_until_fresh?: boolean
  }): AsyncGenerator<GraphResponse>;
}

Call with fresh_only = false, loop_until_fresh = true to get the currently existing graph and keep waiting for a rebuild.

The response will have status GraphResponseStatuses.OLD_GRAPH in the first response, then it will go throught the GraphResponseStatuses.QUEUED, GraphResponseStatuses.IN_PROGRESS states with the progress field set to the percentage of the graph build that is done. When the rebuild is done, the status will be GraphResponseStatuses.FRESH_GRAPH and the loop will stop. The graph_json field will have the graph at each of these responses.