trendsagi 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- trendsagi-0.1.0/LICENSE +0 -0
- trendsagi-0.1.0/PKG-INFO +327 -0
- trendsagi-0.1.0/README.md +308 -0
- trendsagi-0.1.0/pyproject.toml +31 -0
- trendsagi-0.1.0/setup.cfg +4 -0
- trendsagi-0.1.0/src/trendsagi/__init__.py +5 -0
- trendsagi-0.1.0/src/trendsagi/client.py +337 -0
- trendsagi-0.1.0/src/trendsagi/exceptions.py +28 -0
- trendsagi-0.1.0/src/trendsagi/models.py +281 -0
- trendsagi-0.1.0/src/trendsagi.egg-info/PKG-INFO +327 -0
- trendsagi-0.1.0/src/trendsagi.egg-info/SOURCES.txt +12 -0
- trendsagi-0.1.0/src/trendsagi.egg-info/dependency_links.txt +1 -0
- trendsagi-0.1.0/src/trendsagi.egg-info/requires.txt +2 -0
- trendsagi-0.1.0/src/trendsagi.egg-info/top_level.txt +1 -0
trendsagi-0.1.0/LICENSE
ADDED
File without changes
|
trendsagi-0.1.0/PKG-INFO
ADDED
@@ -0,0 +1,327 @@
|
|
1
|
+
Metadata-Version: 2.4
|
2
|
+
Name: trendsagi
|
3
|
+
Version: 0.1.0
|
4
|
+
Summary: The official Python client for the TrendsAGI API.
|
5
|
+
Author-email: TrendsAGI <contact@trendsagi.com>
|
6
|
+
Project-URL: Homepage, https://github.com/TrendsAGI/TrendsAGI
|
7
|
+
Project-URL: Bug Tracker, https://github.com/TrendsAGI/TrendsAGI/issues
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
9
|
+
Classifier: License :: OSI Approved :: MIT License
|
10
|
+
Classifier: Operating System :: OS Independent
|
11
|
+
Classifier: Intended Audience :: Developers
|
12
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
13
|
+
Requires-Python: >=3.8
|
14
|
+
Description-Content-Type: text/markdown
|
15
|
+
License-File: LICENSE
|
16
|
+
Requires-Dist: requests>=2.28.0
|
17
|
+
Requires-Dist: pydantic>=2.0
|
18
|
+
Dynamic: license-file
|
19
|
+
|
20
|
+
# TrendsAGI Official Python Client
|
21
|
+
|
22
|
+
[](https://pypi.org/project/trendsagi/)
|
23
|
+
[](https://opensource.org/licenses/MIT)
|
24
|
+
[](https://pypi.org/project/trendsagi/)
|
25
|
+
|
26
|
+
The official Python client for the [TrendsAGI API](https://trendsagi.com), providing a simple and convenient way to access real-time trend data, AI-powered insights, and the full intelligence suite.
|
27
|
+
|
28
|
+
This library is fully typed with Pydantic models for all API responses, giving you excellent editor support (like autocompletion and type checking) and data validation out of the box.
|
29
|
+
|
30
|
+
## Table of Contents
|
31
|
+
|
32
|
+
- [Features](#features)
|
33
|
+
- [Installation](#installation)
|
34
|
+
- [Getting Started](#getting-started)
|
35
|
+
- [Authentication](#authentication)
|
36
|
+
- [Quickstart Example](#quickstart-example)
|
37
|
+
- [Usage Examples](#usage-examples)
|
38
|
+
- [Get AI-Powered Insights for a Trend](#get-ai-powered-insights-for-a-trend)
|
39
|
+
- [Perform a Deep Analysis on a Topic](#perform-a-deep-analysis-on-a-topic)
|
40
|
+
- [Track an X (Twitter) User](#track-an-x-twitter-user)
|
41
|
+
- [Monitor for Crisis Events](#monitor-for-crisis-events)
|
42
|
+
- [Handling Errors and Exceptions](#handling-errors-and-exceptions)
|
43
|
+
- [Full API Documentation](#full-api-documentation)
|
44
|
+
- [Contributing](#contributing)
|
45
|
+
- [License](#license)
|
46
|
+
|
47
|
+
## Features
|
48
|
+
|
49
|
+
- Access real-time and historical trend data
|
50
|
+
- Leverage powerful AI-driven insights, sentiment analysis, and content briefs for any trend
|
51
|
+
- Perform deep, causal analysis on any topic or query
|
52
|
+
- Utilize the Intelligence Suite for actionable recommendations, crisis monitoring, and market tracking
|
53
|
+
- Manage topic interests, alerts, and data export configurations
|
54
|
+
- Simple, intuitive methods mirroring the API structure
|
55
|
+
- Robust error handling with custom exceptions
|
56
|
+
- Data validation and rich type-hinting powered by Pydantic
|
57
|
+
|
58
|
+
## Installation
|
59
|
+
|
60
|
+
Install the library directly from PyPI:
|
61
|
+
|
62
|
+
```bash
|
63
|
+
pip install trendsagi
|
64
|
+
```
|
65
|
+
|
66
|
+
## Getting Started
|
67
|
+
|
68
|
+
### Authentication
|
69
|
+
|
70
|
+
First, you'll need a TrendsAGI account and an API key. You can sign up and generate a key from your dashboard.
|
71
|
+
|
72
|
+
We strongly recommend storing your API key as an environment variable to avoid committing it to version control.
|
73
|
+
|
74
|
+
```bash
|
75
|
+
export TRENDSAGI_API_KEY="your_api_key_here"
|
76
|
+
```
|
77
|
+
|
78
|
+
### Quickstart Example
|
79
|
+
|
80
|
+
This example demonstrates how to initialize the client and fetch the latest trending topics.
|
81
|
+
|
82
|
+
```python
|
83
|
+
import os
|
84
|
+
import trendsagi
|
85
|
+
from trendsagi import exceptions
|
86
|
+
|
87
|
+
# It's recommended to load your API key from an environment variable
|
88
|
+
API_KEY = os.environ.get("TRENDSAGI_API_KEY")
|
89
|
+
|
90
|
+
if not API_KEY:
|
91
|
+
raise ValueError("Please set the TRENDSAGI_API_KEY environment variable.")
|
92
|
+
|
93
|
+
# Initialize the client
|
94
|
+
client = trendsagi.TrendsAGIClient(api_key=API_KEY)
|
95
|
+
|
96
|
+
try:
|
97
|
+
# Get the top 5 trending topics from the last 24 hours
|
98
|
+
print("Fetching top 5 trending topics...")
|
99
|
+
response = client.get_trends(limit=5, period='24h')
|
100
|
+
|
101
|
+
print(f"\nFound {response.meta.total} total trends. Displaying the top {len(response.trends)}:")
|
102
|
+
for trend in response.trends:
|
103
|
+
print(f"- ID: {trend.id}, Name: '{trend.name}', Volume: {trend.volume}")
|
104
|
+
|
105
|
+
except exceptions.AuthenticationError:
|
106
|
+
print("Authentication failed. Please check your API key.")
|
107
|
+
except exceptions.APIError as e:
|
108
|
+
print(f"An API error occurred: Status {e.status_code}, Details: {e.error_detail}")
|
109
|
+
except exceptions.TrendsAGIError as e:
|
110
|
+
print(f"A client-side error occurred: {e}")
|
111
|
+
```
|
112
|
+
|
113
|
+
## Usage Examples
|
114
|
+
|
115
|
+
### Get AI-Powered Insights for a Trend
|
116
|
+
|
117
|
+
Retrieve AI-generated insights for a specific trend, such as key themes, target audiences, and content ideas.
|
118
|
+
|
119
|
+
```python
|
120
|
+
# Assuming 'client' is an initialized TrendsAGIClient
|
121
|
+
# and you have a trend_id from a call to get_trends()
|
122
|
+
TREND_ID = 12345
|
123
|
+
|
124
|
+
try:
|
125
|
+
print(f"\nGetting AI insights for trend ID {TREND_ID}...")
|
126
|
+
ai_insight = client.get_ai_insights(trend_id=TREND_ID)
|
127
|
+
|
128
|
+
if ai_insight:
|
129
|
+
print(f" Sentiment: {ai_insight.sentiment_category}")
|
130
|
+
print(" Key Themes:")
|
131
|
+
for theme in ai_insight.key_themes[:3]: # show first 3
|
132
|
+
print(f" - {theme}")
|
133
|
+
print(" Suggested Content Angle:")
|
134
|
+
print(f" - {ai_insight.content_brief.key_angles_for_content[0]}")
|
135
|
+
|
136
|
+
except exceptions.NotFoundError:
|
137
|
+
print(f"Trend with ID {TREND_ID} not found.")
|
138
|
+
except exceptions.APIError as e:
|
139
|
+
print(f"An API error occurred: {e}")
|
140
|
+
```
|
141
|
+
|
142
|
+
### Perform a Deep Analysis on a Topic
|
143
|
+
|
144
|
+
```python
|
145
|
+
# Assuming 'client' is an initialized TrendsAGIClient
|
146
|
+
try:
|
147
|
+
print("\nPerforming deep analysis on 'artificial intelligence'...")
|
148
|
+
analysis = client.perform_deep_analysis(
|
149
|
+
query="artificial intelligence",
|
150
|
+
analysis_type="comprehensive"
|
151
|
+
)
|
152
|
+
|
153
|
+
print(f"Analysis completed. Key findings:")
|
154
|
+
print(f"- Market sentiment: {analysis.market_sentiment}")
|
155
|
+
print(f"- Growth trajectory: {analysis.growth_projection}")
|
156
|
+
print(f"- Key influencers: {', '.join(analysis.top_influencers[:3])}")
|
157
|
+
|
158
|
+
except exceptions.APIError as e:
|
159
|
+
print(f"An API error occurred: {e}")
|
160
|
+
```
|
161
|
+
|
162
|
+
### Track an X (Twitter) User
|
163
|
+
|
164
|
+
Add a user to your tracked market entities in the Intelligence Suite.
|
165
|
+
|
166
|
+
```python
|
167
|
+
# Assuming 'client' is an initialized TrendsAGIClient
|
168
|
+
try:
|
169
|
+
print("\nAdding a new X user to track...")
|
170
|
+
new_entity = client.create_tracked_x_user(
|
171
|
+
handle="OpenAI",
|
172
|
+
name="OpenAI",
|
173
|
+
notes="Key player in the AI industry."
|
174
|
+
)
|
175
|
+
print(f"Successfully started tracking '{new_entity.name}' (ID: {new_entity.id})")
|
176
|
+
|
177
|
+
except exceptions.ConflictError:
|
178
|
+
print("This user is already being tracked.")
|
179
|
+
except exceptions.APIError as e:
|
180
|
+
print(f"An API error occurred: {e}")
|
181
|
+
```
|
182
|
+
|
183
|
+
### Monitor for Crisis Events
|
184
|
+
|
185
|
+
Retrieve any active crisis events detected by the system.
|
186
|
+
|
187
|
+
```python
|
188
|
+
# Assuming 'client' is an initialized TrendsAGIClient
|
189
|
+
try:
|
190
|
+
print("\nChecking for active crisis events...")
|
191
|
+
crisis_response = client.get_crisis_events(status='active', limit=5)
|
192
|
+
|
193
|
+
if not crisis_response.events:
|
194
|
+
print("No active crisis events found.")
|
195
|
+
else:
|
196
|
+
for event in crisis_response.events:
|
197
|
+
print(f"- [SEVERITY: {event.severity}] {event.title}")
|
198
|
+
print(f" Summary: {event.summary}\n")
|
199
|
+
|
200
|
+
except exceptions.APIError as e:
|
201
|
+
print(f"An API error occurred: {e}")
|
202
|
+
```
|
203
|
+
|
204
|
+
## Handling Errors and Exceptions
|
205
|
+
|
206
|
+
The library raises specific exceptions for different types of errors, all inheriting from `trendsagi.exceptions.TrendsAGIError`. This allows for granular error handling.
|
207
|
+
|
208
|
+
- **`TrendsAGIError`**: The base exception for all library-specific errors
|
209
|
+
- **`AuthenticationError`**: Raised on 401 errors for an invalid or missing API key
|
210
|
+
- **`APIError`**: The base class for all non-2xx API responses
|
211
|
+
- **`NotFoundError`**: Raised on 404 errors when a resource is not found
|
212
|
+
- **`ConflictError`**: Raised on 409 errors, e.g., when trying to create a resource that already exists
|
213
|
+
- **`RateLimitError`**: Raised on 429 errors when you have exceeded your API rate limit
|
214
|
+
|
215
|
+
Example error handling:
|
216
|
+
|
217
|
+
```python
|
218
|
+
try:
|
219
|
+
response = client.get_trends()
|
220
|
+
except exceptions.AuthenticationError:
|
221
|
+
print("Invalid API key. Please check your credentials.")
|
222
|
+
except exceptions.RateLimitError as e:
|
223
|
+
print(f"Rate limit exceeded. Retry after: {e.retry_after} seconds")
|
224
|
+
except exceptions.NotFoundError:
|
225
|
+
print("The requested resource was not found.")
|
226
|
+
except exceptions.APIError as e:
|
227
|
+
print(f"API error: {e.status_code} - {e.error_detail}")
|
228
|
+
except exceptions.TrendsAGIError as e:
|
229
|
+
print(f"Client error: {e}")
|
230
|
+
```
|
231
|
+
|
232
|
+
## Advanced Usage
|
233
|
+
|
234
|
+
### Working with Pagination
|
235
|
+
|
236
|
+
```python
|
237
|
+
# Get all trends with pagination
|
238
|
+
all_trends = []
|
239
|
+
page = 1
|
240
|
+
while True:
|
241
|
+
response = client.get_trends(page=page, limit=100)
|
242
|
+
all_trends.extend(response.trends)
|
243
|
+
|
244
|
+
if page >= response.meta.total_pages:
|
245
|
+
break
|
246
|
+
page += 1
|
247
|
+
|
248
|
+
print(f"Retrieved {len(all_trends)} total trends")
|
249
|
+
```
|
250
|
+
|
251
|
+
### Setting Up Alerts
|
252
|
+
|
253
|
+
```python
|
254
|
+
# Create a new trend alert
|
255
|
+
alert = client.create_alert(
|
256
|
+
name="AI Technology Alert",
|
257
|
+
keywords=["artificial intelligence", "machine learning", "AI"],
|
258
|
+
threshold_volume=1000,
|
259
|
+
notification_method="email"
|
260
|
+
)
|
261
|
+
print(f"Created alert: {alert.name} (ID: {alert.id})")
|
262
|
+
```
|
263
|
+
|
264
|
+
### Export Data
|
265
|
+
|
266
|
+
```python
|
267
|
+
# Export trend data to CSV
|
268
|
+
export_job = client.export_trends(
|
269
|
+
format="csv",
|
270
|
+
date_range="last_7_days",
|
271
|
+
filters={"category": "technology"}
|
272
|
+
)
|
273
|
+
print(f"Export job started: {export_job.job_id}")
|
274
|
+
|
275
|
+
# Check export status
|
276
|
+
status = client.get_export_status(export_job.job_id)
|
277
|
+
if status.is_complete:
|
278
|
+
print(f"Export ready for download: {status.download_url}")
|
279
|
+
```
|
280
|
+
|
281
|
+
## Full API Documentation
|
282
|
+
|
283
|
+
This library is a client for the TrendsAGI REST API. For complete details on all available API endpoints, parameters, data models, rate limits, and best practices, please refer to our official [API Documentation](https://trendsagi.com/api-docs).
|
284
|
+
|
285
|
+
## Contributing
|
286
|
+
|
287
|
+
Contributions are welcome! If you find a bug or have a feature request, please open an issue on our GitHub Issues page. If you'd like to contribute code, please fork the repository and open a pull request.
|
288
|
+
|
289
|
+
1. Fork the Project
|
290
|
+
2. Create your Feature Branch (`git checkout -b feature/AmazingFeature`)
|
291
|
+
3. Commit your Changes (`git commit -m 'Add some AmazingFeature'`)
|
292
|
+
4. Push to the Branch (`git push origin feature/AmazingFeature`)
|
293
|
+
5. Open a Pull Request
|
294
|
+
|
295
|
+
### Development Setup
|
296
|
+
|
297
|
+
```bash
|
298
|
+
# Clone the repository
|
299
|
+
git clone https://github.com/trendsagi/TrendsAGI.git
|
300
|
+
cd TrendsAGI
|
301
|
+
|
302
|
+
# Install development dependencies
|
303
|
+
pip install -e ".[dev]"
|
304
|
+
|
305
|
+
# Run tests
|
306
|
+
pytest
|
307
|
+
|
308
|
+
# Run linting
|
309
|
+
flake8 trendsagi/
|
310
|
+
mypy trendsagi/
|
311
|
+
```
|
312
|
+
|
313
|
+
## Support
|
314
|
+
|
315
|
+
|
316
|
+
- **API Reference**: [https://trendsagi.com/api-docs](https://trendsagi.com/api-docs)
|
317
|
+
- **Support Email**: contact@trendsagi.com
|
318
|
+
- **GitHub Issues**: [https://github.com/TrendsAGI/TrendsAGI/issues](https://github.com/TrendsAGI/TrendsAGI/issues)
|
319
|
+
|
320
|
+
|
321
|
+
## License
|
322
|
+
|
323
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
324
|
+
|
325
|
+
---
|
326
|
+
|
327
|
+
**Built with ❤️ by the TrendsAGI Team**
|
@@ -0,0 +1,308 @@
|
|
1
|
+
# TrendsAGI Official Python Client
|
2
|
+
|
3
|
+
[](https://pypi.org/project/trendsagi/)
|
4
|
+
[](https://opensource.org/licenses/MIT)
|
5
|
+
[](https://pypi.org/project/trendsagi/)
|
6
|
+
|
7
|
+
The official Python client for the [TrendsAGI API](https://trendsagi.com), providing a simple and convenient way to access real-time trend data, AI-powered insights, and the full intelligence suite.
|
8
|
+
|
9
|
+
This library is fully typed with Pydantic models for all API responses, giving you excellent editor support (like autocompletion and type checking) and data validation out of the box.
|
10
|
+
|
11
|
+
## Table of Contents
|
12
|
+
|
13
|
+
- [Features](#features)
|
14
|
+
- [Installation](#installation)
|
15
|
+
- [Getting Started](#getting-started)
|
16
|
+
- [Authentication](#authentication)
|
17
|
+
- [Quickstart Example](#quickstart-example)
|
18
|
+
- [Usage Examples](#usage-examples)
|
19
|
+
- [Get AI-Powered Insights for a Trend](#get-ai-powered-insights-for-a-trend)
|
20
|
+
- [Perform a Deep Analysis on a Topic](#perform-a-deep-analysis-on-a-topic)
|
21
|
+
- [Track an X (Twitter) User](#track-an-x-twitter-user)
|
22
|
+
- [Monitor for Crisis Events](#monitor-for-crisis-events)
|
23
|
+
- [Handling Errors and Exceptions](#handling-errors-and-exceptions)
|
24
|
+
- [Full API Documentation](#full-api-documentation)
|
25
|
+
- [Contributing](#contributing)
|
26
|
+
- [License](#license)
|
27
|
+
|
28
|
+
## Features
|
29
|
+
|
30
|
+
- Access real-time and historical trend data
|
31
|
+
- Leverage powerful AI-driven insights, sentiment analysis, and content briefs for any trend
|
32
|
+
- Perform deep, causal analysis on any topic or query
|
33
|
+
- Utilize the Intelligence Suite for actionable recommendations, crisis monitoring, and market tracking
|
34
|
+
- Manage topic interests, alerts, and data export configurations
|
35
|
+
- Simple, intuitive methods mirroring the API structure
|
36
|
+
- Robust error handling with custom exceptions
|
37
|
+
- Data validation and rich type-hinting powered by Pydantic
|
38
|
+
|
39
|
+
## Installation
|
40
|
+
|
41
|
+
Install the library directly from PyPI:
|
42
|
+
|
43
|
+
```bash
|
44
|
+
pip install trendsagi
|
45
|
+
```
|
46
|
+
|
47
|
+
## Getting Started
|
48
|
+
|
49
|
+
### Authentication
|
50
|
+
|
51
|
+
First, you'll need a TrendsAGI account and an API key. You can sign up and generate a key from your dashboard.
|
52
|
+
|
53
|
+
We strongly recommend storing your API key as an environment variable to avoid committing it to version control.
|
54
|
+
|
55
|
+
```bash
|
56
|
+
export TRENDSAGI_API_KEY="your_api_key_here"
|
57
|
+
```
|
58
|
+
|
59
|
+
### Quickstart Example
|
60
|
+
|
61
|
+
This example demonstrates how to initialize the client and fetch the latest trending topics.
|
62
|
+
|
63
|
+
```python
|
64
|
+
import os
|
65
|
+
import trendsagi
|
66
|
+
from trendsagi import exceptions
|
67
|
+
|
68
|
+
# It's recommended to load your API key from an environment variable
|
69
|
+
API_KEY = os.environ.get("TRENDSAGI_API_KEY")
|
70
|
+
|
71
|
+
if not API_KEY:
|
72
|
+
raise ValueError("Please set the TRENDSAGI_API_KEY environment variable.")
|
73
|
+
|
74
|
+
# Initialize the client
|
75
|
+
client = trendsagi.TrendsAGIClient(api_key=API_KEY)
|
76
|
+
|
77
|
+
try:
|
78
|
+
# Get the top 5 trending topics from the last 24 hours
|
79
|
+
print("Fetching top 5 trending topics...")
|
80
|
+
response = client.get_trends(limit=5, period='24h')
|
81
|
+
|
82
|
+
print(f"\nFound {response.meta.total} total trends. Displaying the top {len(response.trends)}:")
|
83
|
+
for trend in response.trends:
|
84
|
+
print(f"- ID: {trend.id}, Name: '{trend.name}', Volume: {trend.volume}")
|
85
|
+
|
86
|
+
except exceptions.AuthenticationError:
|
87
|
+
print("Authentication failed. Please check your API key.")
|
88
|
+
except exceptions.APIError as e:
|
89
|
+
print(f"An API error occurred: Status {e.status_code}, Details: {e.error_detail}")
|
90
|
+
except exceptions.TrendsAGIError as e:
|
91
|
+
print(f"A client-side error occurred: {e}")
|
92
|
+
```
|
93
|
+
|
94
|
+
## Usage Examples
|
95
|
+
|
96
|
+
### Get AI-Powered Insights for a Trend
|
97
|
+
|
98
|
+
Retrieve AI-generated insights for a specific trend, such as key themes, target audiences, and content ideas.
|
99
|
+
|
100
|
+
```python
|
101
|
+
# Assuming 'client' is an initialized TrendsAGIClient
|
102
|
+
# and you have a trend_id from a call to get_trends()
|
103
|
+
TREND_ID = 12345
|
104
|
+
|
105
|
+
try:
|
106
|
+
print(f"\nGetting AI insights for trend ID {TREND_ID}...")
|
107
|
+
ai_insight = client.get_ai_insights(trend_id=TREND_ID)
|
108
|
+
|
109
|
+
if ai_insight:
|
110
|
+
print(f" Sentiment: {ai_insight.sentiment_category}")
|
111
|
+
print(" Key Themes:")
|
112
|
+
for theme in ai_insight.key_themes[:3]: # show first 3
|
113
|
+
print(f" - {theme}")
|
114
|
+
print(" Suggested Content Angle:")
|
115
|
+
print(f" - {ai_insight.content_brief.key_angles_for_content[0]}")
|
116
|
+
|
117
|
+
except exceptions.NotFoundError:
|
118
|
+
print(f"Trend with ID {TREND_ID} not found.")
|
119
|
+
except exceptions.APIError as e:
|
120
|
+
print(f"An API error occurred: {e}")
|
121
|
+
```
|
122
|
+
|
123
|
+
### Perform a Deep Analysis on a Topic
|
124
|
+
|
125
|
+
```python
|
126
|
+
# Assuming 'client' is an initialized TrendsAGIClient
|
127
|
+
try:
|
128
|
+
print("\nPerforming deep analysis on 'artificial intelligence'...")
|
129
|
+
analysis = client.perform_deep_analysis(
|
130
|
+
query="artificial intelligence",
|
131
|
+
analysis_type="comprehensive"
|
132
|
+
)
|
133
|
+
|
134
|
+
print(f"Analysis completed. Key findings:")
|
135
|
+
print(f"- Market sentiment: {analysis.market_sentiment}")
|
136
|
+
print(f"- Growth trajectory: {analysis.growth_projection}")
|
137
|
+
print(f"- Key influencers: {', '.join(analysis.top_influencers[:3])}")
|
138
|
+
|
139
|
+
except exceptions.APIError as e:
|
140
|
+
print(f"An API error occurred: {e}")
|
141
|
+
```
|
142
|
+
|
143
|
+
### Track an X (Twitter) User
|
144
|
+
|
145
|
+
Add a user to your tracked market entities in the Intelligence Suite.
|
146
|
+
|
147
|
+
```python
|
148
|
+
# Assuming 'client' is an initialized TrendsAGIClient
|
149
|
+
try:
|
150
|
+
print("\nAdding a new X user to track...")
|
151
|
+
new_entity = client.create_tracked_x_user(
|
152
|
+
handle="OpenAI",
|
153
|
+
name="OpenAI",
|
154
|
+
notes="Key player in the AI industry."
|
155
|
+
)
|
156
|
+
print(f"Successfully started tracking '{new_entity.name}' (ID: {new_entity.id})")
|
157
|
+
|
158
|
+
except exceptions.ConflictError:
|
159
|
+
print("This user is already being tracked.")
|
160
|
+
except exceptions.APIError as e:
|
161
|
+
print(f"An API error occurred: {e}")
|
162
|
+
```
|
163
|
+
|
164
|
+
### Monitor for Crisis Events
|
165
|
+
|
166
|
+
Retrieve any active crisis events detected by the system.
|
167
|
+
|
168
|
+
```python
|
169
|
+
# Assuming 'client' is an initialized TrendsAGIClient
|
170
|
+
try:
|
171
|
+
print("\nChecking for active crisis events...")
|
172
|
+
crisis_response = client.get_crisis_events(status='active', limit=5)
|
173
|
+
|
174
|
+
if not crisis_response.events:
|
175
|
+
print("No active crisis events found.")
|
176
|
+
else:
|
177
|
+
for event in crisis_response.events:
|
178
|
+
print(f"- [SEVERITY: {event.severity}] {event.title}")
|
179
|
+
print(f" Summary: {event.summary}\n")
|
180
|
+
|
181
|
+
except exceptions.APIError as e:
|
182
|
+
print(f"An API error occurred: {e}")
|
183
|
+
```
|
184
|
+
|
185
|
+
## Handling Errors and Exceptions
|
186
|
+
|
187
|
+
The library raises specific exceptions for different types of errors, all inheriting from `trendsagi.exceptions.TrendsAGIError`. This allows for granular error handling.
|
188
|
+
|
189
|
+
- **`TrendsAGIError`**: The base exception for all library-specific errors
|
190
|
+
- **`AuthenticationError`**: Raised on 401 errors for an invalid or missing API key
|
191
|
+
- **`APIError`**: The base class for all non-2xx API responses
|
192
|
+
- **`NotFoundError`**: Raised on 404 errors when a resource is not found
|
193
|
+
- **`ConflictError`**: Raised on 409 errors, e.g., when trying to create a resource that already exists
|
194
|
+
- **`RateLimitError`**: Raised on 429 errors when you have exceeded your API rate limit
|
195
|
+
|
196
|
+
Example error handling:
|
197
|
+
|
198
|
+
```python
|
199
|
+
try:
|
200
|
+
response = client.get_trends()
|
201
|
+
except exceptions.AuthenticationError:
|
202
|
+
print("Invalid API key. Please check your credentials.")
|
203
|
+
except exceptions.RateLimitError as e:
|
204
|
+
print(f"Rate limit exceeded. Retry after: {e.retry_after} seconds")
|
205
|
+
except exceptions.NotFoundError:
|
206
|
+
print("The requested resource was not found.")
|
207
|
+
except exceptions.APIError as e:
|
208
|
+
print(f"API error: {e.status_code} - {e.error_detail}")
|
209
|
+
except exceptions.TrendsAGIError as e:
|
210
|
+
print(f"Client error: {e}")
|
211
|
+
```
|
212
|
+
|
213
|
+
## Advanced Usage
|
214
|
+
|
215
|
+
### Working with Pagination
|
216
|
+
|
217
|
+
```python
|
218
|
+
# Get all trends with pagination
|
219
|
+
all_trends = []
|
220
|
+
page = 1
|
221
|
+
while True:
|
222
|
+
response = client.get_trends(page=page, limit=100)
|
223
|
+
all_trends.extend(response.trends)
|
224
|
+
|
225
|
+
if page >= response.meta.total_pages:
|
226
|
+
break
|
227
|
+
page += 1
|
228
|
+
|
229
|
+
print(f"Retrieved {len(all_trends)} total trends")
|
230
|
+
```
|
231
|
+
|
232
|
+
### Setting Up Alerts
|
233
|
+
|
234
|
+
```python
|
235
|
+
# Create a new trend alert
|
236
|
+
alert = client.create_alert(
|
237
|
+
name="AI Technology Alert",
|
238
|
+
keywords=["artificial intelligence", "machine learning", "AI"],
|
239
|
+
threshold_volume=1000,
|
240
|
+
notification_method="email"
|
241
|
+
)
|
242
|
+
print(f"Created alert: {alert.name} (ID: {alert.id})")
|
243
|
+
```
|
244
|
+
|
245
|
+
### Export Data
|
246
|
+
|
247
|
+
```python
|
248
|
+
# Export trend data to CSV
|
249
|
+
export_job = client.export_trends(
|
250
|
+
format="csv",
|
251
|
+
date_range="last_7_days",
|
252
|
+
filters={"category": "technology"}
|
253
|
+
)
|
254
|
+
print(f"Export job started: {export_job.job_id}")
|
255
|
+
|
256
|
+
# Check export status
|
257
|
+
status = client.get_export_status(export_job.job_id)
|
258
|
+
if status.is_complete:
|
259
|
+
print(f"Export ready for download: {status.download_url}")
|
260
|
+
```
|
261
|
+
|
262
|
+
## Full API Documentation
|
263
|
+
|
264
|
+
This library is a client for the TrendsAGI REST API. For complete details on all available API endpoints, parameters, data models, rate limits, and best practices, please refer to our official [API Documentation](https://trendsagi.com/api-docs).
|
265
|
+
|
266
|
+
## Contributing
|
267
|
+
|
268
|
+
Contributions are welcome! If you find a bug or have a feature request, please open an issue on our GitHub Issues page. If you'd like to contribute code, please fork the repository and open a pull request.
|
269
|
+
|
270
|
+
1. Fork the Project
|
271
|
+
2. Create your Feature Branch (`git checkout -b feature/AmazingFeature`)
|
272
|
+
3. Commit your Changes (`git commit -m 'Add some AmazingFeature'`)
|
273
|
+
4. Push to the Branch (`git push origin feature/AmazingFeature`)
|
274
|
+
5. Open a Pull Request
|
275
|
+
|
276
|
+
### Development Setup
|
277
|
+
|
278
|
+
```bash
|
279
|
+
# Clone the repository
|
280
|
+
git clone https://github.com/trendsagi/TrendsAGI.git
|
281
|
+
cd TrendsAGI
|
282
|
+
|
283
|
+
# Install development dependencies
|
284
|
+
pip install -e ".[dev]"
|
285
|
+
|
286
|
+
# Run tests
|
287
|
+
pytest
|
288
|
+
|
289
|
+
# Run linting
|
290
|
+
flake8 trendsagi/
|
291
|
+
mypy trendsagi/
|
292
|
+
```
|
293
|
+
|
294
|
+
## Support
|
295
|
+
|
296
|
+
|
297
|
+
- **API Reference**: [https://trendsagi.com/api-docs](https://trendsagi.com/api-docs)
|
298
|
+
- **Support Email**: contact@trendsagi.com
|
299
|
+
- **GitHub Issues**: [https://github.com/TrendsAGI/TrendsAGI/issues](https://github.com/TrendsAGI/TrendsAGI/issues)
|
300
|
+
|
301
|
+
|
302
|
+
## License
|
303
|
+
|
304
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
305
|
+
|
306
|
+
---
|
307
|
+
|
308
|
+
**Built with ❤️ by the TrendsAGI Team**
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# File: trendsagi-client/pyproject.toml
|
2
|
+
|
3
|
+
[build-system]
|
4
|
+
requires = ["setuptools>=61.0"]
|
5
|
+
build-backend = "setuptools.build_meta"
|
6
|
+
|
7
|
+
[project]
|
8
|
+
name = "trendsagi"
|
9
|
+
version = "0.1.0"
|
10
|
+
authors = [
|
11
|
+
{ name="TrendsAGI", email="contact@trendsagi.com" },
|
12
|
+
]
|
13
|
+
description = "The official Python client for the TrendsAGI API."
|
14
|
+
readme = "README.md"
|
15
|
+
license = { file="LICENSE" }
|
16
|
+
requires-python = ">=3.8"
|
17
|
+
classifiers = [
|
18
|
+
"Programming Language :: Python :: 3",
|
19
|
+
"License :: OSI Approved :: MIT License",
|
20
|
+
"Operating System :: OS Independent",
|
21
|
+
"Intended Audience :: Developers",
|
22
|
+
"Topic :: Software Development :: Libraries :: Python Modules",
|
23
|
+
]
|
24
|
+
dependencies = [
|
25
|
+
"requests>=2.28.0",
|
26
|
+
"pydantic>=2.0"
|
27
|
+
]
|
28
|
+
|
29
|
+
[project.urls]
|
30
|
+
"Homepage" = "https://github.com/TrendsAGI/TrendsAGI"
|
31
|
+
"Bug Tracker" = "https://github.com/TrendsAGI/TrendsAGI/issues"
|
@@ -0,0 +1,5 @@
|
|
1
|
+
# File: trendsagi/__init__.py
|
2
|
+
|
3
|
+
from .client import TrendsAGIClient # Assuming TrendsAGIClient is in trendsagi/client.py
|
4
|
+
from . import exceptions # Assuming exceptions are defined in trendsagi/exceptions.py
|
5
|
+
# Or: from .errors import exceptions if it's in trendsagi/errors.py
|