Skip to main content

A plug-n-play package fetch test data from WPT and parse for specific keys

Project description

WPT Parser

Upload Python Package

Getting Started

  • Prerequisites

    • Python >= 3.6.x
    • pip
  • Installation

    $ pip install wpt-parser
    
  • Examples

    • Using the JSON Parser
    # import the class
    from WPTParser.Fetch import Fetch
    from WPTParser.JSONParser import JSONParser
    
    test_json = Fetch().json()
    keys = ['data.median.firstView.loadTime',]
    # returns a new dict with specified keys
    JSONParser(test_json).pick(keys=keys).exec()
    
    
  • Key Types:

    • key_name

      • Works like simple JSON extraction. Provide the name of the key and boom!.
      • For extraction from beyond first level, append keys with a separator and provide key_delimiter for the program to recognize the start of next level.
      • Example:
      """
      {
          keylevel11: {
              keylevel21: value,
              keylevel22: {
                  keylevel31: value
              }
          }
      }
      """
      # key to extract first level
      # keylevel11
      # returns {keylevel21: ...}
      
      # key to extract second level, first key
      # keylevel11.keylevel21
      # returns value
      
    • [list_index]

      • When you have a list as value and you want to extract a specific index value/object.
      • For extraction from beyond first level, append keys with a separator and provide key_delimiter for the program to recognize the start of next level.
      • Example:
      """
      {
          keylevel11: {
              keylevel21: [
                  1, 2, 3
              ],
              keylevel22: {
                  keylevel31: value
              }
          }
      }
      """
      # key to extract second level, third index
      # keylevel11.keylevel21.[2]
      # returns 3
      
    • [{key=value}]

      • When you have a unordered list of object and you want extract a specific object from the list based on the key and value inside the object
      • For extraction from beyond first level, append keys with a separator and provide key_delimiter for the program to recognize the start of next level.
      • Example:
      """
      {
          keylevel11: {
              keylevel21: [
                  1, 2, 3
              ],
              keylevel22: {
                  keylevel31: value
              },
              keylevel23: [
                  {
                      name: Awesome,
                  },
                  {
                      name: Package
                  }
              ]
          }
      }
      """
      # key to extract second level, and from that extarct the object with name = Awesome
      # keylevel11.keylevel23.[{name=Awesome}]
      # return {name: Awesome}
      
    • [{key~regex}]

      • When you have a unordered list of object and you want extract a specific object from the list based on the key and a regex of value inside the object
      • For extraction from beyond first level, append keys with a separator and provide key_delimiter for the program to recognize the start of next level.
      • The regex search is case sensitive. You do not need to add // or r'' to write your regex.
      • The search will find all the matches and return a list
      • Example:
      """
      {
          keylevel11: {
              keylevel21: [
                  1, 2, 3
              ],
              keylevel22: {
                  keylevel31: value
              },
              keylevel23: [
                  {
                      name: Awesome123,
                  },
                  {
                      name: Package
                  }
              ]
          }
      }
      """
      # key to extract second level, and from that extarct the object with name matching Awesome
      # keylevel11.keylevel23.[{name~Awesome}]
      # return [{name: Awesome}]
      

Available Methods

  • JSONParser
Method Params type default Description
pick key str None selects a key to be returned
pick keys list [] selects a list key to be returned
pick key_delimiter str "." Separator used to identify multi level JSON
pick key_mapping dict {} Mapping of keys for picking with custom key name.
  • Fetch
Method Params type default Description
json test_id str None test_id for a wpt or a speed curve test
json WPT_URI str 'https://webpagetest.org' URI for your WPT instance

Note:

  • The package is under development and will be prone to more frequent updates

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

wpt-parser-0.0.6.tar.gz (5.3 kB view details)

Uploaded Source

File details

Details for the file wpt-parser-0.0.6.tar.gz.

File metadata

  • Download URL: wpt-parser-0.0.6.tar.gz
  • Upload date:
  • Size: 5.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.7.6

File hashes

Hashes for wpt-parser-0.0.6.tar.gz
Algorithm Hash digest
SHA256 1fbfc310a122f9f3e5a36433cd2ccfe7f4137ee894a61b3ae69c5e0d8c5dac2c
MD5 2a029cf756dfdc8a7c3b70e1c03cb88d
BLAKE2b-256 421aa4b3b23945651dc57d4e0c5168796b60fa3890e36e78187d16fa45c15ba0

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page