openapi: 3.0.0
info:
  title: Kaggle Notebook Search API
  description: |
    Search Kaggle's public notebooks by keyword, or list the notebooks that use a Kaggle dataset or competition, with Kaggle's sorts and a language filter.

    Each notebook carries its ref (`notebook_id`), title, whether it is a notebook or a script, votes, views and comments. When Kaggle supplies them, results also include the author and tier, language, last run and creation times, medal, tags, runtime and the competitions, datasets, notebooks and models it reads. Kaggle lists 20 notebooks per page, and this API serves up to 50 pages (1,000 notebooks) for a search.

    **Cross-linking**: `notebook_id` is the `author/slug` ref of the notebook's Kaggle page. `dataset_id` takes the ref the Kaggle Dataset Search API returns, and a competition source's `competition_id` feeds this API's `competition_id`.
  version: 1.0.0
servers:
  - url: https://www.searchapi.io/api/v1
paths:
  /search:
    get:
      summary: Kaggle Notebook Search
      security:
        - ApiKeyAuth: []
        - ApiKeyQuery: []
      parameters:
        - name: engine
          in: query
          required: true
          description: 'Search engine. Must be set to: `kaggle_notebook_search`'
          schema:
            type: string
            enum: ["kaggle_notebook_search"]
        - name: q
          in: query
          required: false
          description: The terms to search for. Required unless `dataset_id` or `competition_id` is set.
          schema:
            type: string
            maxLength: 512
        - name: language
          in: query
          required: false
          description: Only notebooks in this language.
          schema:
            type: string
            enum: ["python", "r"]
        - name: sort_by
          in: query
          required: false
          description: Order of the notebooks. `hotness` is Kaggle's own ranking, `recently_run` puts the latest run first and `recently_created` the newest notebook first.
          schema:
            type: string
            enum: ["hotness", "votes", "comments", "recently_run", "recently_created"]
            default: "hotness"
        - name: dataset_id
          in: query
          required: false
          description: Only notebooks that use this Kaggle dataset, as an `owner/slug` ref such as `imdevskp/corona-virus-report` or its kaggle.com/datasets URL. A dataset Kaggle has no public page for returns an error. Can't be combined with `competition_id`.
          schema:
            type: string
        - name: competition_id
          in: query
          required: false
          description: Only notebooks that use this Kaggle competition, by its numeric id, such as `3136` for Titanic. Can't be combined with `dataset_id`.
          schema:
            type: integer
            minimum: 1
            maximum: 2147483647
        - name: page
          in: query
          required: false
          description: Page of results, 20 notebooks per page.
          schema:
            type: integer
            minimum: 1
            maximum: 50
            default: 1
        - name: zero_retention
          in: query
          required: false
          description: Set to true to keep request parameters, HTML, and JSON responses out of storage and logs. Enterprise plans only.
          schema:
            type: boolean
            default: false
      responses:
        '200':
          description: Successful response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SearchResponse'
        '400':
          description: Validation Error. There is an issue with query parameters, such as missing required parameters or invalid values.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '401':
          description: Authentication Error. The API key is missing or invalid.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '403':
          description: Forbidden. Zero data retention is not available to the account, or the account requires `zero_retention=true`.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '429':
          description: Rate Limit Exceeded. The number of allowed requests has been exceeded. Consider upgrading your plan or waiting for the limit to reset.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '500':
          description: Server Error. Internal server error.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '503':
          description: Timeout. We could not retrieve results in 90 seconds.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
components:
  securitySchemes:
    ApiKeyAuth:
      type: apiKey
      in: header
      name: Authorization
      description: 'Use Bearer authentication. Format: "Bearer YOUR_API_KEY"'
    ApiKeyQuery:
      type: apiKey
      in: query
      name: api_key
      description: Pass API key as query parameter
  schemas:
    SearchResponse:
      type: object
      properties:
        search_metadata:
          $ref: '#/components/schemas/SearchMetadata'
        search_parameters:
          $ref: '#/components/schemas/SearchParameters'
        notebook_results:
          type: array
          description: Notebooks Kaggle lists for the search, in Kaggle's order.
          items:
            $ref: '#/components/schemas/Notebook'
        pagination:
          $ref: '#/components/schemas/Pagination'
        error:
          type: string
          description: Message saying why no notebooks were returned.
    Notebook:
      type: object
      required: [position, notebook_id, id, title, link, type, votes, views, comments]
      properties:
        position:
          type: integer
          description: Position of the notebook in the results, counting from the first page.
        notebook_id:
          type: string
          description: Kaggle's ref for the notebook, its author's username and the notebook's slug.
        id:
          type: integer
          description: Kaggle's numeric id for the notebook.
        title:
          type: string
          description: Title of the notebook.
        link:
          type: string
          description: Link to the notebook's page on Kaggle.
        author:
          $ref: '#/components/schemas/Author'
        language:
          type: string
          description: Language the notebook is written in, such as `python` or `r`.
        type:
          type: string
          description: Whether this is a notebook or a script.
          enum: ["notebook", "script"]
        votes:
          type: integer
          description: Number of upvotes.
        views:
          type: integer
          description: Number of views.
        comments:
          type: integer
          description: Number of comments.
        medal:
          type: string
          description: Medal Kaggle awarded the notebook.
          enum: ["gold", "silver", "bronze"]
        tags:
          type: array
          description: Names of the tags the notebook carries.
          items:
            type: string
        best_public_score:
          type: number
          description: Best public leaderboard score of the notebook's competition submissions.
        is_fork:
          type: boolean
          description: Whether the notebook is a copy of another notebook.
        forked_from:
          $ref: '#/components/schemas/ForkedFrom'
        last_run_at:
          type: string
          format: date-time
          description: Time of the notebook's last run, in UTC.
        created_at:
          type: string
          format: date-time
          description: Time the notebook was created, in UTC.
        runtime_seconds:
          type: integer
          description: Duration of the last run, in seconds.
        lines:
          type: integer
          description: Number of lines in the notebook.
        has_data_outputs:
          type: boolean
          description: Whether the notebook's latest version saved output files.
        data_sources:
          type: array
          description: Competitions, datasets, notebook outputs and models the notebook reads.
          items:
            $ref: '#/components/schemas/DataSource'
    Author:
      type: object
      required: [username, link]
      properties:
        username:
          type: string
          description: Kaggle username.
        name:
          type: string
          description: Display name.
        link:
          type: string
          description: Link to the user's profile on Kaggle.
        tier:
          type: string
          description: The user's Kaggle progression tier, such as `expert`, `master` or `grandmaster`.
    ForkedFrom:
      type: object
      required: [notebook_id, link, author]
      properties:
        notebook_id:
          type: string
          description: Kaggle's ref for the original notebook.
        id:
          type: integer
          description: Kaggle's numeric id for the original notebook.
        link:
          type: string
          description: Link to the original notebook's page on Kaggle.
        author:
          $ref: '#/components/schemas/Author'
    DataSource:
      type: object
      required: [type]
      properties:
        type:
          type: string
          description: Kind of source.
          enum: ["competition", "dataset", "notebook", "model"]
        name:
          type: string
          description: Name of the source.
        link:
          type: string
          description: Link to the source's page on Kaggle.
        competition_id:
          type: integer
          description: Kaggle's numeric id for a competition source.
        dataset_id:
          type: string
          description: Kaggle's ref for a dataset source, its owner's slug and the dataset's slug.
        notebook_id:
          type: string
          description: Kaggle's ref for a notebook whose output the notebook reads.
        model_id:
          type: string
          description: Kaggle's ref for a model source, its owner's slug and the model's slug.
        is_private:
          type: boolean
          description: Whether the source is private, so Kaggle shows only its kind.
    Pagination:
      type: object
      required: [current]
      properties:
        current:
          type: integer
          description: Number of this page.
        next:
          type: integer
          description: Number of the next page.
    SearchMetadata:
      type: object
      required: [status, created_at]
      properties:
        id:
          type: string
          description: "Unique identifier for the search request"
        status:
          type: string
          description: "Status of the search request"
        created_at:
          type: string
          format: date-time
          description: "Timestamp when the search was created"
        request_time_taken:
          type: number
          description: "Time taken to make the request in seconds"
        parsing_time_taken:
          type: number
          description: "Time taken to parse the results in seconds"
        total_time_taken:
          type: number
          description: "Total time taken for the search in seconds"
        request_url:
          type: string
          description: "Kaggle notebook search page for this search"
        html_url:
          type: string
          description: "URL to view HTML results"
        json_url:
          type: string
          description: "URL to view JSON results"
    SearchParameters:
      type: object
      properties:
        engine:
          type: string
          description: Search engine used
        q:
          type: string
          description: The terms searched for
        language:
          type: string
          description: Language of the notebooks
        sort_by:
          type: string
          description: Order of the notebooks
        dataset_id:
          type: string
          description: Kaggle dataset the notebooks use
        competition_id:
          type: integer
          description: Kaggle competition the notebooks use
        page:
          type: integer
          description: Page of results
        zero_retention:
          type: boolean
          description: Whether zero data retention was requested
    ErrorResponse:
      type: object
      required: [error]
      properties:
        error:
          type: string
          description: Error message describing what went wrong
