For the latest source, discussions, bug reports, etc., please visit the GitHub repository
PredictHQ API Client for Python
PredictHQ is the demand intelligence company combining real-world events into one global source of truth to help businesses better understand demand and plan for the future.
Installation
The PredictHQ Python client is distributed as a pip package. You can simply install it by running
pip install predicthq
Migrating from version <= 2.4.0
If you are migrating to version 3.0.0 or above from an earlier version, please check the V3 breaking changes details.
If you are migrating to version 4.0.0 or above from an earlier version, please check the V4 breaking changes details.
Usage
We support all the endpoints available in our API.
oauth2
accounts
broadcasts
events
features
places
radius
Please refer to our API Documentation for a description of each endpoint.
The usecases/ folder is a good starting point to get familiar with the Python SDK.
You can also review the tests/ for a kitchen sink of all the parameters available per endpoint.
By default the search() method only returns the first page of results, with a default page size of 10.
from predicthq import Client
phq = Client(access_token="abc123")
for event in phq.events.search():
print(event.rank, event.category, event.title, event.start.strftime("%Y-%m-%d"))
You can chain the iter_all() generator to iterate over all your events.
for event in phq.events.search().iter_all():
print(event.rank, event.category, event.title, event.start.strftime("%Y-%m-%d"))
Events endpoint
Additional examples are available in usecases/events folder.
The following example searches for the Katy Perry events (full text search) with rank level of 4 or 5 (rank >= 60) in the concerts category.
from predicthq import Client
phq = Client(access_token="abc123")
for event in phq.events.search(q="Katy Perry", rank_level=[4, 5], category="concerts"):
print(event.rank, event.category, event.title, event.start.strftime("%Y-%m-%d"))
The following example searches for the New York places (full text search) in the US.
from predicthq import Client
phq = Client(access_token="abc123")
for place in phq.places.search(q="New York", country="US"):
print(place.id, place.name, place.type, place.location)
All search results can be serialized into a dictionary using the .model_dump() method call.
To keep None values use .model_dump()
To remove None values use .model_dump(exclude_none=True)
Examples:
from predicthq import Client
phq = Client(access_token="abc123")
for event in phq.events.search(q="Katy Perry", rank_level=[4, 5], category="concerts"):
# Serialize event data into a dictionary and remove None valuesprint(event.model_dump(exclude_none=True))
from predicthq import Client
phq = Client(access_token="abc123")
for feature in phq.features.obtain_features(
active__gte="2024-12-31",
active__lte="2025-01-02",
location__place_id=["4671654"],
phq_rank_public_holidays=True,
phq_attendance_sports__stats=["count", "median"],
phq_attendance_sports__phq_rank={
"gt": 50
}
):
# Serialize feature data into a dictionary and remove None valuesprint(feature.model_dump(exclude_none=True))
Config parameters
We support some config parameters for additional flexibility.
Supported config parameters:
verify_ssl
from predicthq import Client
phq = Client(access_token="abc123")
# double underscore syntaxfor event in phq.events.search(config__verify_ssl=False):
print(event.rank, event.category, event.title, event.start.strftime("%Y-%m-%d"))
# dictionary syntaxfor event in phq.events.search(config={"verify_ssl": False}):
print(event.rank, event.category, event.title, event.start.strftime("%Y-%m-%d"))
We found that predicthq demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago.It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.