pypartpicker


Namepypartpicker JSON
Version 1.9.5 PyPI version JSON
download
home_pagehttps://github.com/thefakequake/pypartpicker
SummaryA package that scrapes pcpartpicker.com and returns the results as objects.
upload_time2023-12-01 16:49:45
maintainer
docs_urlNone
author
requires_python
license
keywords pcpartpicker scraper list beautifulsoup pc parts
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # PyPartPicker

#### PyPartPicker is a package that allows you to obtain information from PCPartPicker quickly and easily, with data being returned via objects with numerous attributes.

---
### Features:
- Obtain Part objects, estimated wattage and total cost from PCPartPicker lists.
- Obtain name, product URL, price, product type, image and more from Part objects.
- Obtain everything previously mentioned + specs, reviews and in depth pricing information from PCPartPicker product links.
- Async ready: all scraping methods have an asynchronous version


# Installation

---
Installation via pip:
```
>>> pip install pypartpicker
```
Or clone the repo directly:
```
>>> git clone https://github.com/thefakequake/pypartpicker.git
```
# Example programs

---

Here is a program that searches for i7's, prints every result, then gets the first result and prints its specs:
```python
from pypartpicker import Scraper

# creates the scraper object
pcpp = Scraper()
# returns a list of Part objects we can iterate through
parts = pcpp.part_search("i7")

# iterates through every part object
for part in parts:
    # prints the name of the part
    print(part.name)

# gets the first product and fetches its URL
first_product_url = parts[0].url
# gets the Product object for the item
product = pcpp.fetch_product(first_product_url)
# prints the product's specs using the specs attribute
print(product.specs)
```
Here is another program that finds i3s that are cheaper than or equal to £110, prints their specs and then prints the first review:
```python
from pypartpicker import Scraper
from time import sleep

# returns a list of Part objects we can iterate through
# the region is set to "uk" so that we get prices in GBP
pcpp = Scraper()
parts = pcpp.part_search("i3", region="uk")

# iterates through the parts
for part in parts:
    # checks if the price is lower than 110
    if float(part.price.strip("£")) <= 110:
        print(f"I found a valid product: {part.name}")
        print(f"Here is the link: {part.url}")
        # gets the product object for the parts
        product = pcpp.fetch_product(part.url)
        print(product.specs)
        # makes sure the product has reviews
        if product.reviews != None:
            # gets the first review
            review = product.reviews[0]
            print(f"Posted by {review.author}: {review.content}")
            print(f"They rated this product {review.rating}/5.")
        else:
            print("There are no reviews on this product!")
            
    # slows down the program so as not to spam PCPartPicker and potentially get IP banned
    sleep(3)
```

# Creating the Scraper object

---

### `Scraper(headers={...}, response_retriever=...)`

### Parameters
- **headers** ( [dict](https://docs.python.org/3/library/stdtypes.html#mapping-types-dict) ) - The browser headers for the requests in a dict.

  Note: There are headers set by default. I only recommend changing them if you are encountering scraping errors.

- **response_retriever** ( [Callable](https://docs.python.org/3/library/typing.html#typing.Callable) ) - A function accepting arguments (`url, **kwargs`) that is called to retrieve the response from PCPartPicker

  Note: A default retriever is configured that calls pcpartpicker.com directly. I only recommend changing this if you need to configure how the request is made (e.g. via a proxy)

# Scraper Methods

---

### `Scraper.part_search(search_term, limit=20, region=None)`
#### Returns Part objects using PCPartPicker's search function.
### **Parameters**
- **search_term** ( [str](https://docs.python.org/3/library/stdtypes.html#str) ) - The term you want to search for.
  
    Example: `"i5"`
  

- **limit** (Optional[ [int](https://docs.python.org/3/library/functions.html#int) ]) - The amount of results that you want to be returned.
    
    Example: `limit=5`
  

- **region** (Optional[ [str](https://docs.python.org/3/library/stdtypes.html#str) ]) - The country code of which you want the pricing for the Part objects to be in. 
    
    Example: `region="uk"`
  
### Returns
A list of Part objects corresponding to the results on PCPartPicker.


---

### `Scraper.fetch_product(product_url)`
#### Returns a Product object from a PCPartPicker product URL.
### **Parameters**
- **product_url** ( [str](https://docs.python.org/3/library/stdtypes.html#str) ) - The product URL for the product you want to search for.
  
    Example: `"https://pcpartpicker.com/product/9nm323/amd-ryzen-5-3600-36-thz-6-core-processor-100-100000031box"`

### Returns
A Product object for the part.

---
### `Scraper.fetch_list(list_url)`
#### Returns a PCPPLIst object from a PCPartPicker list URL.
### **Parameters**
- **list_url** ( [str](https://docs.python.org/3/library/stdtypes.html#str) ) - The URL for the parts list.
  
    Example: `"https://pcpartpicker.com/list/Tzx22V"`

### Returns
A PCPPList object for the list.

# Other methods

---

### `get_list_links(string)`
#### Returns a list of PCPartPicker list links from the given string.
### **Parameters**
- **string** ( [str](https://docs.python.org/3/library/stdtypes.html#str) ) - The string containing the parts list URL.
  
    Example: `"this function can extract the link from this string https://pcpartpicker.com/list/Tzx22V"`

### Returns
A list of URLs.

---
### `get_product_links(string)`
#### Returns a list of PCPartPicker product links from the given string.
### **Parameters**
- **string** ( [str](https://docs.python.org/3/library/stdtypes.html#str) ) - The string containing the product URL.
  
    Example: `"this function can extract the link from this string https://pcpartpicker.com/product/9nm323/amd-ryzen-5-3600-36-thz-6-core-processor-100-100000031box"`

### Returns
A list of URLs.


# Async Methods
___
#### Same syntax as sync functions, but add aio_ to the beginning of the method name and add await before the function call.
#### For example:
```python
pcpp = Scraper()
results = pcpp.part_search("i5")
```

becomes

```python
pcpp = Scraper()
results = await pcpp.aio_part_search("i5")
```

Remember: you can only call async functions within other async functions. If you are not writing async code, do not use these methods. Use the sync methods, which don't have aio_ before their name.

Only the blocking functions (the ones that involve active scraping) have async equivalents.

# Objects

---
## Part
### Attributes
- `name` - The name of the part
- `url` - The product URL for the part
- `type` - The type of the part (e.g. CPU, Motherboard, Memory)
- `price` - The cheapest price for the part
- `image` - The image link for the part

---

## Product
### Attributes

- All attributes from Part
- `specs` - The specs for the product, arranged in a dictionary with the values being lists
- `price_list` - A list of Price objects containing all the merchants, prices and stock values
- `rating` - The total user ratings and average score for the product
- `reviews` - A list of Review objects for the product
- `compatible_parts` - A list of tuples containing the compatible parts links for the product

___

## Price
### Attributes

- `value` - The final price value
- `base_value` - The price value before shipping and other discounts
- `seller` - The name of the company selling the part
- `seller_icon` - The icon URL for the company selling the part
- `url` - The URL which links to the seller's product listing
- `in_stock` - A boolean of whether the product is in stock

---

## Review
### Attributes

- `author` - The name of the person who posted the review
- `author_url` - The URL which points to the author's profile
- `author_icon` - The icon URL of the person who posted the review
- `points` - The amount of upvotes on the review
- `created_at` - How long ago the review was sent
- `rating` - The star rating out of 5 of the product that the review gives
- `content` - The text content of the review

---

## PCPPList
### Attributes

- `parts` - List of Part objects corresponding to every part in the list
- `wattage` - The estimated wattage for the parts in the list
- `total` - The total price of the PCPartPicker list
- `url` - The URL of the PCPartPicker list
- `compatibility` - A list containing the compatibility notes for the parts list

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/thefakequake/pypartpicker",
    "name": "pypartpicker",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "pcpartpicker,scraper,list,beautifulsoup,pc,parts",
    "author": "",
    "author_email": "",
    "download_url": "https://files.pythonhosted.org/packages/0c/e5/5c854e2a868ef0ce22638c4889beb6eaa788231c3acca45e1c92be6c76aa/pypartpicker-1.9.5.tar.gz",
    "platform": null,
    "description": "# PyPartPicker\r\n\r\n#### PyPartPicker is a package that allows you to obtain information from PCPartPicker quickly and easily, with data being returned via objects with numerous attributes.\r\n\r\n---\r\n### Features:\r\n- Obtain Part objects, estimated wattage and total cost from PCPartPicker lists.\r\n- Obtain name, product URL, price, product type, image and more from Part objects.\r\n- Obtain everything previously mentioned + specs, reviews and in depth pricing information from PCPartPicker product links.\r\n- Async ready: all scraping methods have an asynchronous version\r\n\r\n\r\n# Installation\r\n\r\n---\r\nInstallation via pip:\r\n```\r\n>>> pip install pypartpicker\r\n```\r\nOr clone the repo directly:\r\n```\r\n>>> git clone https://github.com/thefakequake/pypartpicker.git\r\n```\r\n# Example programs\r\n\r\n---\r\n\r\nHere is a program that searches for i7's, prints every result, then gets the first result and prints its specs:\r\n```python\r\nfrom pypartpicker import Scraper\r\n\r\n# creates the scraper object\r\npcpp = Scraper()\r\n# returns a list of Part objects we can iterate through\r\nparts = pcpp.part_search(\"i7\")\r\n\r\n# iterates through every part object\r\nfor part in parts:\r\n    # prints the name of the part\r\n    print(part.name)\r\n\r\n# gets the first product and fetches its URL\r\nfirst_product_url = parts[0].url\r\n# gets the Product object for the item\r\nproduct = pcpp.fetch_product(first_product_url)\r\n# prints the product's specs using the specs attribute\r\nprint(product.specs)\r\n```\r\nHere is another program that finds i3s that are cheaper than or equal to \u00a3110, prints their specs and then prints the first review:\r\n```python\r\nfrom pypartpicker import Scraper\r\nfrom time import sleep\r\n\r\n# returns a list of Part objects we can iterate through\r\n# the region is set to \"uk\" so that we get prices in GBP\r\npcpp = Scraper()\r\nparts = pcpp.part_search(\"i3\", region=\"uk\")\r\n\r\n# iterates through the parts\r\nfor part in parts:\r\n    # checks if the price is lower than 110\r\n    if float(part.price.strip(\"\u00a3\")) <= 110:\r\n        print(f\"I found a valid product: {part.name}\")\r\n        print(f\"Here is the link: {part.url}\")\r\n        # gets the product object for the parts\r\n        product = pcpp.fetch_product(part.url)\r\n        print(product.specs)\r\n        # makes sure the product has reviews\r\n        if product.reviews != None:\r\n            # gets the first review\r\n            review = product.reviews[0]\r\n            print(f\"Posted by {review.author}: {review.content}\")\r\n            print(f\"They rated this product {review.rating}/5.\")\r\n        else:\r\n            print(\"There are no reviews on this product!\")\r\n            \r\n    # slows down the program so as not to spam PCPartPicker and potentially get IP banned\r\n    sleep(3)\r\n```\r\n\r\n# Creating the Scraper object\r\n\r\n---\r\n\r\n### `Scraper(headers={...}, response_retriever=...)`\r\n\r\n### Parameters\r\n- **headers** ( [dict](https://docs.python.org/3/library/stdtypes.html#mapping-types-dict) ) - The browser headers for the requests in a dict.\r\n\r\n  Note: There are headers set by default. I only recommend changing them if you are encountering scraping errors.\r\n\r\n- **response_retriever** ( [Callable](https://docs.python.org/3/library/typing.html#typing.Callable) ) - A function accepting arguments (`url, **kwargs`) that is called to retrieve the response from PCPartPicker\r\n\r\n  Note: A default retriever is configured that calls pcpartpicker.com directly. I only recommend changing this if you need to configure how the request is made (e.g. via a proxy)\r\n\r\n# Scraper Methods\r\n\r\n---\r\n\r\n### `Scraper.part_search(search_term, limit=20, region=None)`\r\n#### Returns Part objects using PCPartPicker's search function.\r\n### **Parameters**\r\n- **search_term** ( [str](https://docs.python.org/3/library/stdtypes.html#str) ) - The term you want to search for.\r\n  \r\n    Example: `\"i5\"`\r\n  \r\n\r\n- **limit** (Optional[ [int](https://docs.python.org/3/library/functions.html#int) ]) - The amount of results that you want to be returned.\r\n    \r\n    Example: `limit=5`\r\n  \r\n\r\n- **region** (Optional[ [str](https://docs.python.org/3/library/stdtypes.html#str) ]) - The country code of which you want the pricing for the Part objects to be in. \r\n    \r\n    Example: `region=\"uk\"`\r\n  \r\n### Returns\r\nA list of Part objects corresponding to the results on PCPartPicker.\r\n\r\n\r\n---\r\n\r\n### `Scraper.fetch_product(product_url)`\r\n#### Returns a Product object from a PCPartPicker product URL.\r\n### **Parameters**\r\n- **product_url** ( [str](https://docs.python.org/3/library/stdtypes.html#str) ) - The product URL for the product you want to search for.\r\n  \r\n    Example: `\"https://pcpartpicker.com/product/9nm323/amd-ryzen-5-3600-36-thz-6-core-processor-100-100000031box\"`\r\n\r\n### Returns\r\nA Product object for the part.\r\n\r\n---\r\n### `Scraper.fetch_list(list_url)`\r\n#### Returns a PCPPLIst object from a PCPartPicker list URL.\r\n### **Parameters**\r\n- **list_url** ( [str](https://docs.python.org/3/library/stdtypes.html#str) ) - The URL for the parts list.\r\n  \r\n    Example: `\"https://pcpartpicker.com/list/Tzx22V\"`\r\n\r\n### Returns\r\nA PCPPList object for the list.\r\n\r\n# Other methods\r\n\r\n---\r\n\r\n### `get_list_links(string)`\r\n#### Returns a list of PCPartPicker list links from the given string.\r\n### **Parameters**\r\n- **string** ( [str](https://docs.python.org/3/library/stdtypes.html#str) ) - The string containing the parts list URL.\r\n  \r\n    Example: `\"this function can extract the link from this string https://pcpartpicker.com/list/Tzx22V\"`\r\n\r\n### Returns\r\nA list of URLs.\r\n\r\n---\r\n### `get_product_links(string)`\r\n#### Returns a list of PCPartPicker product links from the given string.\r\n### **Parameters**\r\n- **string** ( [str](https://docs.python.org/3/library/stdtypes.html#str) ) - The string containing the product URL.\r\n  \r\n    Example: `\"this function can extract the link from this string https://pcpartpicker.com/product/9nm323/amd-ryzen-5-3600-36-thz-6-core-processor-100-100000031box\"`\r\n\r\n### Returns\r\nA list of URLs.\r\n\r\n\r\n# Async Methods\r\n___\r\n#### Same syntax as sync functions, but add aio_ to the beginning of the method name and add await before the function call.\r\n#### For example:\r\n```python\r\npcpp = Scraper()\r\nresults = pcpp.part_search(\"i5\")\r\n```\r\n\r\nbecomes\r\n\r\n```python\r\npcpp = Scraper()\r\nresults = await pcpp.aio_part_search(\"i5\")\r\n```\r\n\r\nRemember: you can only call async functions within other async functions. If you are not writing async code, do not use these methods. Use the sync methods, which don't have aio_ before their name.\r\n\r\nOnly the blocking functions (the ones that involve active scraping) have async equivalents.\r\n\r\n# Objects\r\n\r\n---\r\n## Part\r\n### Attributes\r\n- `name` - The name of the part\r\n- `url` - The product URL for the part\r\n- `type` - The type of the part (e.g. CPU, Motherboard, Memory)\r\n- `price` - The cheapest price for the part\r\n- `image` - The image link for the part\r\n\r\n---\r\n\r\n## Product\r\n### Attributes\r\n\r\n- All attributes from Part\r\n- `specs` - The specs for the product, arranged in a dictionary with the values being lists\r\n- `price_list` - A list of Price objects containing all the merchants, prices and stock values\r\n- `rating` - The total user ratings and average score for the product\r\n- `reviews` - A list of Review objects for the product\r\n- `compatible_parts` - A list of tuples containing the compatible parts links for the product\r\n\r\n___\r\n\r\n## Price\r\n### Attributes\r\n\r\n- `value` - The final price value\r\n- `base_value` - The price value before shipping and other discounts\r\n- `seller` - The name of the company selling the part\r\n- `seller_icon` - The icon URL for the company selling the part\r\n- `url` - The URL which links to the seller's product listing\r\n- `in_stock` - A boolean of whether the product is in stock\r\n\r\n---\r\n\r\n## Review\r\n### Attributes\r\n\r\n- `author` - The name of the person who posted the review\r\n- `author_url` - The URL which points to the author's profile\r\n- `author_icon` - The icon URL of the person who posted the review\r\n- `points` - The amount of upvotes on the review\r\n- `created_at` - How long ago the review was sent\r\n- `rating` - The star rating out of 5 of the product that the review gives\r\n- `content` - The text content of the review\r\n\r\n---\r\n\r\n## PCPPList\r\n### Attributes\r\n\r\n- `parts` - List of Part objects corresponding to every part in the list\r\n- `wattage` - The estimated wattage for the parts in the list\r\n- `total` - The total price of the PCPartPicker list\r\n- `url` - The URL of the PCPartPicker list\r\n- `compatibility` - A list containing the compatibility notes for the parts list\r\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "A package that scrapes pcpartpicker.com and returns the results as objects.",
    "version": "1.9.5",
    "project_urls": {
        "Download": "https://github.com/thefakequake/pypartpicker/archive/refs/tags/v1.9.5.tar.gz",
        "Homepage": "https://github.com/thefakequake/pypartpicker"
    },
    "split_keywords": [
        "pcpartpicker",
        "scraper",
        "list",
        "beautifulsoup",
        "pc",
        "parts"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "2d9a9c130d06374e6a2d94526eda85971ebf6f956bf718cf650999c44f76a85f",
                "md5": "e966055b63630bc23fd28d553f006b02",
                "sha256": "28cdb332c3f9b07b59caa52e39387d5dc6e5fee2f406eb6e74784cc8a635db1d"
            },
            "downloads": -1,
            "filename": "pypartpicker-1.9.5-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "e966055b63630bc23fd28d553f006b02",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 10179,
            "upload_time": "2023-12-01T16:49:43",
            "upload_time_iso_8601": "2023-12-01T16:49:43.266913Z",
            "url": "https://files.pythonhosted.org/packages/2d/9a/9c130d06374e6a2d94526eda85971ebf6f956bf718cf650999c44f76a85f/pypartpicker-1.9.5-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "0ce55c854e2a868ef0ce22638c4889beb6eaa788231c3acca45e1c92be6c76aa",
                "md5": "412c47ff8941ac3aa60977d97c90e824",
                "sha256": "275a93d47253e9cd5fc9e2588de3d7a1190618b58f48b85bdcb0384c1ef534f7"
            },
            "downloads": -1,
            "filename": "pypartpicker-1.9.5.tar.gz",
            "has_sig": false,
            "md5_digest": "412c47ff8941ac3aa60977d97c90e824",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 12480,
            "upload_time": "2023-12-01T16:49:45",
            "upload_time_iso_8601": "2023-12-01T16:49:45.784029Z",
            "url": "https://files.pythonhosted.org/packages/0c/e5/5c854e2a868ef0ce22638c4889beb6eaa788231c3acca45e1c92be6c76aa/pypartpicker-1.9.5.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-12-01 16:49:45",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "thefakequake",
    "github_project": "pypartpicker",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [],
    "lcname": "pypartpicker"
}
        
Elapsed time: 0.15965s