Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@leetnotion/leetcode-api

JacobLinCool516MIT1.10.0TypeScript support: included

Get user profiles, submissions, and problems on LeetCode.

leetcode, api

readme

LeetCode Query

The API to get user profiles, submissions, and problems on LeetCode, with highly customizable GraphQL API and Rate Limiter.

Features

Without Authentication

  • <input checked="" disabled="" type="checkbox"> Get Public User Profile.
  • <input checked="" disabled="" type="checkbox"> Get User's Recent Submissions. (Public, Max: 20)
  • <input checked="" disabled="" type="checkbox"> Get User Contest Records. (thanks to @laporchen)
  • <input checked="" disabled="" type="checkbox"> Get All Problem List, or with filter of difficulty and tags.
  • <input checked="" disabled="" type="checkbox"> Get Problem Detail.
  • <input checked="" disabled="" type="checkbox"> Get Daily Challenge.

Authenticated

  • <input checked="" disabled="" type="checkbox"> Get All Submissions of The Authenticated User.
  • <input checked="" disabled="" type="checkbox"> Get Submission Details, including the code and percentiles.

Other

  • <input checked="" disabled="" type="checkbox"> Customable GraphQL Query API.
  • <input checked="" disabled="" type="checkbox"> Customable Rate Limiter. (Default: 20 req / 10 sec)
  • <input checked="" disabled="" type="checkbox"> Customable Fetcher.

Examples

Get An User's Public Profile

Includes recent submissions and posts.

import { LeetCode } from 'leetcode-query';

const leetcode = new LeetCode();
const user = await leetcode.user('username');

Get All Of Your Submissions

import { LeetCode, Credential } from 'leetcode-query';

const credential = new Credential();
await credential.init('YOUR-LEETCODE-SESSION-COOKIE');

const leetcode = new LeetCode(credential);
console.log(await leetcode.submissions(100, 0));

Use Custom Fetcher

You can use your own fetcher, for example, fetch through a real browser.

import { LeetCode, fetcher } from 'leetcode-query';
import { chromium } from 'playwright-extra';
import stealth from 'puppeteer-extra-plugin-stealth';

// setup browser
const _browser = chromium.use(stealth()).launch();
const _page = _browser
    .then((browser) => browser.newPage())
    .then(async (page) => {
        await page.goto('https://leetcode.com');
        return page;
    });

// use a custom fetcher
fetcher.set(async (...args) => {
    const page = await _page;

    const res = await page.evaluate(async (args) => {
        const res = await fetch(...args);
        return {
            body: await res.text(),
            status: res.status,
            statusText: res.statusText,
            headers: Object.fromEntries(res.headers),
        };
    }, args);

    return new Response(res.body, res);
});

// use as normal
const lc = new LeetCode();
const daily = await lc.daily();
console.log(daily);
await _browser.then((browser) => browser.close());

Documentation

Documentation for this package is available on https://jacoblincool.github.io/LeetCode-Query/.

changelog

leetcode-query

2.0.1

Patch Changes

2.0.0

Major Changes

  • #105 2a777b1 Thanks @jinzcdev! - ## Breaking Changes

    • submission method: Now uses GraphQL query to fetch submission details, resulting in significant changes to return structure:
      • Removed problem_id field, replaced by question.questionId
      • Removed manually calculated percentiles (runtime_percentile and memory_percentile), replaced by API-provided runtimePercentile and memoryPercentile values
      • Removed details field with submission data
      • Return structure now directly matches GraphQL response format instead of the previous custom format

    New Features

    • Added submission_detail GraphQL API query support, fixing API errors for leetcode.com
    • Added user_progress_questions method to retrieve user progress with filters for leetcode.com

1.3.0

Minor Changes

1.2.3

Patch Changes

1.2.2

Patch Changes

1.2.1

Patch Changes

1.2.0

Minor Changes

1.1.0

Minor Changes

1.0.1

Patch Changes

1.0.0

Major Changes