Skip to main content

A Python library for fetching car data from CarQueryAPI

Project description

CarQuery

CarQuery is a Python library that enables you to effortlessly gather comprehensive car model data from the Car Query API and export it into a CSV format. With robust filtering capabilities, you can refine your search based on manufacturer, model, variant, production year, and more. Dive into the world of automotive data with ease and flexibility!


Features

  • Comprehensive Data: Fetch detailed car model information from the Car Query API.
  • Flexible Filtering: Refine your search by specifying:
    • Manufacturer
    • Model
    • Variant
    • Production year range
    • Whether the car is sold in the US
  • Exclusion Words: Exclude specific words from variant names to tailor your results.
  • Export to CSV: Save filtered data to a CSV file for further analysis and visualization.

Installation

You can install CarQuery directly from PyPI:

pip install carquery

Usage

Here’s how you can use the library in your Python projects.

Import the Library

from carquery import fetch_models, fetch_car_data, write_to_csv, print_table

Fetching Models

To fetch all models for a specific manufacturer:

make = "Honda"
models = fetch_models(make)
print("Available Models:")
print_table(models)

Fetching Car Data

You can fetch detailed car data using various filters:

make = "Honda"
model = "Civic"  # Leave empty for all models
variant = ""  # Leave empty for all variants
from_year = 2010
to_year = 2022
sold_in_us = True  # Set to True, False, or None for all

car_data = fetch_car_data(make=make, model=model, variant=variant, from_year=from_year, to_year=to_year, sold_in_us=sold_in_us)
print(f"Fetched {len(car_data)} car entries.")

Exporting to CSV

You can export the fetched data to a CSV file for further analysis:

filename = f"{make}_{model}_car_data.csv"
write_to_csv(filename, car_data)
print(f"Data has been saved to {filename}")

Excluding Specific Words from Variants

You can filter out variants containing specific words by processing the car_data list before exporting:

exclusion_words = ["Touring", "Sport"]

filtered_car_data = [
    entry for entry in car_data
    if not any(word.lower() in entry['vehicle_variant'].lower() for word in exclusion_words)
]

filename = f"{make}_{model}_filtered_car_data.csv"
write_to_csv(filename, filtered_car_data)
print(f"Filtered data has been saved to {filename}")

Example: Full Workflow

Here’s a complete example that uses all features:

from carquery import fetch_models, fetch_car_data, write_to_csv, print_table

# Fetch models for a manufacturer
make = "Honda"
models = fetch_models(make)
print("Available Models:")
print_table(models)

# Fetch detailed car data
model = "Civic"
car_data = fetch_car_data(make=make, model=model, from_year=2010, to_year=2022, sold_in_us=True)
print(f"Fetched {len(car_data)} car entries.")

# Exclude specific words from variants
exclusion_words = ["Touring", "Sport"]
filtered_car_data = [
    entry for entry in car_data
    if not any(word.lower() in entry['vehicle_variant'].lower() for word in exclusion_words)
]

# Save to CSV
filename = f"{make}_{model}_filtered_car_data.csv"
write_to_csv(filename, filtered_car_data)
print(f"Filtered data has been saved to {filename}")

Dependencies

This library requires the following Python packages:

  • requests
  • prettytable
  • tqdm

These will be automatically installed when you install the library via pip.


Contributing

Contributions are welcome! Please follow these steps:

  1. Fork the repository.
  2. Create a new branch for your feature or bug fix.
  3. Submit a pull request explaining your changes.

License

This library is distributed under the MIT License. See the LICENSE file for more details.


Support

If you encounter any issues or have questions, feel free to open an issue on the GitHub repository.

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

carquery-0.1.0.tar.gz (4.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

carquery-0.1.0-py3-none-any.whl (4.6 kB view details)

Uploaded Python 3

File details

Details for the file carquery-0.1.0.tar.gz.

File metadata

  • Download URL: carquery-0.1.0.tar.gz
  • Upload date:
  • Size: 4.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.13.1

File hashes

Hashes for carquery-0.1.0.tar.gz
Algorithm Hash digest
SHA256 4749b19dd35664090870b11ec426e8b8a99981f1031b7da76d2cdcdb4b6c9142
MD5 c5337e60598a1c996cc4b68e039acecb
BLAKE2b-256 2f9e4b4e112350c6f091a7077fb9f941aa8a6e0a870a04d8c4ddee8da0239ef8

See more details on using hashes here.

File details

Details for the file carquery-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: carquery-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 4.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.13.1

File hashes

Hashes for carquery-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8833aaff875098a08559472ccb00241f029d93115d80557ff6bee3a7b4d44138
MD5 1054ec1e8a5fe116024f416a24beff8a
BLAKE2b-256 f5b977291406ca8a1da68b03fefc0d96d245bd11785fa376b9822fbd2e7cfb45

See more details on using hashes here.

Supported by

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