|
1 | 1 | # python-demandapi-client
|
2 | 2 |
|
| 3 | +[](https://pypi.org/project/dynatademand/) |
| 4 | + |
3 | 5 | <a href="https://github.com/dynata/python-demandapi-client/actions?query=branch%3Adev"><img alt="GitHub Actions status" src="https://github.com/dynata/python-demandapi-client/workflows/python-tests/badge.svg"></a>
|
4 | 6 |
|
5 | 7 | A Python client library for the [Dynata Demand API](https://developers.dynata.com/). There are also [go](https://github.com/researchnow/go-samplifyapi-client) and [.NET](https://github.com/researchnow/dotnet-samplifyapi-client) clients available.
|
6 | 8 |
|
7 | 9 | ## Setup
|
8 | 10 |
|
9 |
| -The client requires environment variables to be set for the Dynata Demand API credentials. These can be found in `.env-example`. |
| 11 | +You can install the Demand API client with: |
| 12 | + |
| 13 | + pip install dynatademand |
| 14 | + |
| 15 | +You can provide your Demand API credentials in a couple of ways. They can be set in the environment (a sample config is provided in `.env-example`) or you can provide them while creating the client object. |
10 | 16 |
|
11 | 17 | ## Example Usage
|
12 | 18 |
|
13 |
| - demandapi = DemandAPIClient() |
14 |
| - demandapi.authenticate() |
15 |
| - demandapi.logout() |
| 19 | +```python |
| 20 | +# You can optionally provide your credentials here instead of environment variables. |
| 21 | +demandapi = DemandAPIClient("client_id", "username", "password") |
| 22 | +demandapi.authenticate() |
| 23 | + |
| 24 | +# Any function requiring one or more IDs should be provided as positional arguments. |
| 25 | +demandapi.get_project(7) |
| 26 | + |
| 27 | +# Provide query parameters as keyword-arguments. |
| 28 | +demandapi.get_projects(state="LAUNCHED") |
| 29 | + |
| 30 | +# Functions that send data in a request body accept a python dictionary. |
| 31 | +# Your data will be validated against the schemas provided in the Demand API documentation. |
| 32 | +project_data = { |
| 33 | + 'title': 'My New Survey', |
| 34 | + ... |
| 35 | +} |
| 36 | +demandapi.create_project(project_data) |
| 37 | +``` |
16 | 38 |
|
17 | 39 | ## Supported API Functions
|
18 | 40 |
|
| 41 | +Links to the Demand API documentation are included for each function. |
| 42 | + |
19 | 43 | ### Authentication Functions
|
20 | 44 |
|
21 |
| -authenticate() |
22 |
| -refresh_access_token() |
23 |
| -logout() |
| 45 | +[Obtain Access Token](https://developers.dynata.com/demand-api-reference/authentication/authentication/post-token): authenticate() |
| 46 | +[Refresh Access Token](https://developers.dynata.com/demand-api-reference/authentication/authentication/post-token-refresh): refresh_access_token() |
| 47 | +[Logout](https://developers.dynata.com/demand-api-reference/authentication/authentication/post-logout): logout() |
24 | 48 |
|
25 | 49 | ### Event Functions
|
26 | 50 |
|
27 |
| -get_event(event_id) |
28 |
| -get_events(\*\*kwargs) |
| 51 | +[Get Event](https://developers.dynata.com/demand-api-reference/notifications/events/get-event): get_event(event_id) |
| 52 | +[Get Events](https://developers.dynata.com/demand-api-reference/notifications/events/get-events): get_events(\*\*kwargs) |
29 | 53 |
|
30 | 54 | ### Project Functions
|
31 | 55 |
|
32 |
| -buy_project(project_id, buy_data) |
33 |
| -close_project(project_id) |
34 |
| -create_project(project_data) |
35 |
| -get_project(project_id) |
36 |
| -get_projects(\*\*kwargs) |
37 |
| -reconcile_project(project_id, reconcile_data) |
38 |
| -update_project(project_id, update_data) |
39 |
| -get_project_detailed_report(project_id) |
40 |
| -get_feasibility(project_id) |
41 |
| -get_invoice(project_id) |
| 56 | +[Buy Project](https://developers.dynata.com/demand-api-reference/core-resources/projects/post-project-buy): buy_project(project_id, buy_data) |
| 57 | +[Close Project](https://developers.dynata.com/demand-api-reference/core-resources/projects/post-close-project): close_project(project_id) |
| 58 | +[Create Project](https://developers.dynata.com/demand-api-reference/core-resources/projects/post-projects): create_project(project_data) |
| 59 | +[Get Project](https://developers.dynata.com/demand-api-reference/core-resources/projects/get-project): get_project(project_id) |
| 60 | +[Get Projects](https://developers.dynata.com/demand-api-reference/core-resources/projects/get-projects): get_projects(\*\*kwargs) |
| 61 | +[Update Project](https://developers.dynata.com/demand-api-reference/core-resources/projects/post-project): update_project(project_id, update_data) |
| 62 | +[Get Project Detailed Report](https://developers.dynata.com/demand-api-reference/core-resources/projects/get-project-detailed-report): get_project_detailed_report(project_id) |
| 63 | +[Get Pricing & Feasibility](https://developers.dynata.com/demand-api-reference/core-resources/pricing-feasibility/get-pricing-feasibility): get_feasibility(project_id) |
| 64 | +[Get Invoice PDF](https://developers.dynata.com/demand-api-reference/billing_invoicing/invoicing/get-invoices): get_invoice(project_id) |
42 | 65 |
|
43 | 66 | ### Line Item Functions
|
44 | 67 |
|
45 |
| -add_line_item(project_id, lineitem_data) |
46 |
| -close_line_item(project_id, line_item_id) |
47 |
| -get_line_item(project_id, line_item_id) |
48 |
| -get_line_items(project_id, \*\*kwargs) |
49 |
| -launch_line_item(project_id, line_item_id) |
50 |
| -pause_line_item(project_id, line_item_id) |
51 |
| -update_line_item(project_id, line_item_id, line_item_data) |
52 |
| -get_line_item_detailed_report(project_id, line_item_id) |
| 68 | +[Add Line Item](https://developers.dynata.com/demand-api-reference/core-resources/lineitems/post-lineitems): add_line_item(project_id, lineitem_data) |
| 69 | +[Close Line Item](https://developers.dynata.com/demand-api-reference/core-resources/lineitems/post-lineitem-close): close_line_item(project_id, line_item_id) |
| 70 | +[Get Line Item](https://developers.dynata.com/demand-api-reference/core-resources/lineitems/get-lineitem): get_line_item(project_id, line_item_id) |
| 71 | +[Get Line Items](https://developers.dynata.com/demand-api-reference/core-resources/lineitems/get-lineitems): get_line_items(project_id, \*\*kwargs) |
| 72 | +[Launch Line Item](https://developers.dynata.com/demand-api-reference/core-resources/lineitems/post-lineitem-launch): launch_line_item(project_id, line_item_id) |
| 73 | +[Pause Line Item](https://developers.dynata.com/demand-api-reference/core-resources/lineitems/post-lineitem-pause): pause_line_item(project_id, line_item_id) |
| 74 | +[Update Line Item](https://developers.dynata.com/demand-api-reference/core-resources/lineitems/post-lineitem): update_line_item(project_id, line_item_id, line_item_data) |
| 75 | +[Get Line Item Detailed Report](https://developers.dynata.com/demand-api-reference/core-resources/lineitems/get-detailed-line-item): get_line_item_detailed_report(project_id, line_item_id) |
53 | 76 |
|
54 | 77 | ### Misc Functions
|
55 | 78 |
|
56 |
| -get_attributes(country_code, language_code, \*\*kwargs) |
57 |
| -get_countries(\*\*kwargs) |
58 |
| -get_sources() |
59 |
| -get_survey_topics(\*\*kwargs) |
| 79 | +[Get Attributes](https://developers.dynata.com/demand-api-reference/data_endpoints/attributes/get-attributes): get_attributes(country_code, language_code, \*\*kwargs) |
| 80 | +[Get Countries](https://developers.dynata.com/demand-api-reference/data_endpoints/countries-languages/get-countries): get_countries(\*\*kwargs) |
| 81 | +[Get Sources](https://developers.dynata.com/demand-api-reference/data_endpoints/supplier-sources/get-sources): get_sources() |
| 82 | +[Get Survey Topics](https://developers.dynata.com/demand-api-reference/data_endpoints/categories/get-survey-topic): get_survey_topics(\*\*kwargs) |
60 | 83 |
|
61 | 84 | ## Contributing
|
62 | 85 |
|
63 | 86 | Information on [contributing](CONTRIBUTING.md).
|
64 | 87 |
|
65 | 88 | ## Testing
|
66 | 89 |
|
67 |
| -To run the tests, |
| 90 | +To run the tests, you will need to install the development requirements to your environment. It's recommended to create a virtual environment for your installation to avoid any package conflicts. |
| 91 | + |
| 92 | +You can check out the code by running: |
| 93 | + |
| 94 | + git clone https://github.com/dynata/python-demandapi-client.git |
| 95 | + cd python-demandapi-client |
68 | 96 |
|
| 97 | +And you can create an environment by running: |
| 98 | + |
| 99 | + # If you're using Python 2.7 |
69 | 100 | virtualenv venv
|
70 |
| - . venv/bin/activate |
| 101 | + |
| 102 | + # Or if you're using Python 3: |
| 103 | + python3 -m venv venv |
| 104 | + |
| 105 | + source venv/bin/activate |
71 | 106 | pip install -r requirements.txt
|
72 |
| - pytest tests |
73 |
| - deactivate |
74 | 107 |
|
75 |
| -to run the tests for this project. |
| 108 | +While your virtual environment is activated, you can run `pytest tests` to run the tests. |
0 commit comments