openapi: 3.0.0
info:
  title: Kaggle Dataset Search API
  description: |
    Search Kaggle's public datasets by keyword, owner or tag, with Kaggle's sorts and its file type, licence and size filters.

    Each dataset carries its ref (`dataset_id`), title, owner, licence, votes, downloads, views, notebook count, usability rating out of 10, listed size, last update and tags. Kaggle lists 20 datasets per page and at most 500 pages for a search.

    **Cross-linking**: `dataset_id` is the `owner/slug` ref Kaggle uses for a dataset, as in its dataset page link.
  version: 1.0.0
servers:
  - url: https://www.searchapi.io/api/v1
paths:
  /search:
    get:
      summary: Kaggle Dataset Search
      security:
        - ApiKeyAuth: []
        - ApiKeyQuery: []
      parameters:
        - name: engine
          in: query
          required: true
          description: 'Search engine. Must be set to: `kaggle_dataset_search`'
          schema:
            type: string
            enum: ["kaggle_dataset_search"]
        - name: q
          in: query
          required: false
          description: The terms to search for. Required unless `owner` or `tag` is set.
          schema:
            type: string
            maxLength: 512
        - name: owner
          in: query
          required: false
          description: Kaggle username whose datasets to list. Kaggle matches users only, so an organization returns no datasets.
          schema:
            type: string
            pattern: '^[A-Za-z0-9][A-Za-z0-9_-]{0,63}$'
        - name: tag
          in: query
          required: false
          description: One Kaggle tag, such as `diseases`. Kaggle also matches datasets carrying one of the tag's subtags, such as `covid19` for `diseases`. A tag Kaggle doesn't have returns an error naming it.
          schema:
            type: string
            maxLength: 64
        - name: sort_by
          in: query
          required: false
          description: Order of the datasets. `published` puts the newest first. `downloads` and `notebooks` follow Kaggle's own ranking, which can differ slightly from the counts returned.
          schema:
            type: string
            enum: ["hottest", "votes", "updated", "published", "active", "usability", "downloads", "notebooks"]
            default: "hottest"
        - name: file_type
          in: query
          required: false
          description: Only datasets with files of this type.
          schema:
            type: string
            enum: ["csv", "json", "sqlite", "parquet", "bigquery"]
        - name: license
          in: query
          required: false
          description: Only datasets under a licence of this group. `cc` is Creative Commons, `gpl` the GNU licences, `odb` the Open Data Commons licences, and `other` any other licence.
          schema:
            type: string
            enum: ["cc", "gpl", "odb", "other"]
        - name: min_size
          in: query
          required: false
          description: Smallest dataset size in bytes. Kaggle applies the bounds to its own record of a dataset's size, which can differ from `size_bytes`, most often for datasets with many versions.
          schema:
            type: integer
            minimum: 0
            maximum: 10000000000000
        - name: max_size
          in: query
          required: false
          description: Largest dataset size in bytes. Must be at least `min_size`.
          schema:
            type: integer
            minimum: 1
            maximum: 10000000000000
        - name: page
          in: query
          required: false
          description: Page of results, 20 datasets per page.
          schema:
            type: integer
            minimum: 1
            maximum: 500
            default: 1
      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'
        '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'
        dataset_results:
          type: array
          description: Datasets Kaggle lists for the search, in Kaggle's order.
          items:
            $ref: '#/components/schemas/Dataset'
        pagination:
          $ref: '#/components/schemas/Pagination'
        error:
          type: string
          description: Message saying why no datasets were returned.
    Dataset:
      type: object
      required: [position, dataset_id, id, title, link, owner, votes, downloads, views, notebooks]
      properties:
        position:
          type: integer
          description: Position of the dataset in the results, counting from the first page.
        dataset_id:
          type: string
          description: Kaggle's ref for the dataset, its owner's slug and the dataset's slug.
        id:
          type: integer
          description: Kaggle's numeric id for the dataset.
        title:
          type: string
          description: Title of the dataset.
        subtitle:
          type: string
          description: Subtitle the owner gave the dataset.
        link:
          type: string
          description: Link to the dataset's page on Kaggle.
        owner:
          $ref: '#/components/schemas/Profile'
        creator:
          $ref: '#/components/schemas/Profile'
        license:
          type: string
          description: Name of the dataset's licence.
        votes:
          type: integer
          description: Number of upvotes.
        downloads:
          type: integer
          description: Number of downloads.
        views:
          type: integer
          description: Number of views.
        notebooks:
          type: integer
          description: Number of public notebooks that use the dataset.
        usability_rating:
          type: number
          description: Kaggle's usability rating out of 10, with one decimal.
        size_bytes:
          type: integer
          description: Size Kaggle lists for the dataset, in bytes.
        last_updated:
          type: string
          format: date-time
          description: Time of the dataset's last update, in UTC.
        version:
          type: integer
          description: Number of the dataset's current version.
        tags:
          type: array
          description: Names of the tags the dataset carries.
          items:
            type: string
        thumbnail:
          type: string
          description: Link to the dataset's thumbnail image.
    Profile:
      type: object
      required: [username, link]
      properties:
        username:
          type: string
          description: Kaggle username, or an organization's slug.
        name:
          type: string
          description: Display name.
        link:
          type: string
          description: Link to the profile or organization page on Kaggle.
        is_organization:
          type: boolean
          description: Whether this is a Kaggle organization rather than a user.
    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 dataset list 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
        owner:
          type: string
          description: Kaggle username whose datasets were listed
        tag:
          type: string
          description: Kaggle tag the datasets carry
        sort_by:
          type: string
          description: Order of the datasets
        file_type:
          type: string
          description: File type the datasets have
        license:
          type: string
          description: Licence group of the datasets
        min_size:
          type: integer
          description: Smallest dataset size in bytes
        max_size:
          type: integer
          description: Largest dataset size in bytes
        page:
          type: integer
          description: Page of results
    ErrorResponse:
      type: object
      required: [error]
      properties:
        error:
          type: string
          description: Error message describing what went wrong
