Giter Site home page Giter Site logo

bharat23 / wpt-parser Goto Github PK

View Code? Open in Web Editor NEW
1.0 2.0 0.0 1.3 MB

A python package to fetch and extract test results from Webpagetest, speed curve and other webpagetest backed products.

Home Page: https://pypi.org/project/wpt-parser/

License: MIT License

Python 100.00%
python3 webpagetest speedcurve parser json

wpt-parser's Introduction

WPT Parser

PyPI version 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

wpt-parser's People

Contributors

bharat23 avatar dependabot[bot] avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.