|
1 | | -# maproulette-python-client |
| 1 | +# MapRoulette - A Python Client for the MapRoulette API |
| 2 | + |
| 3 | +https://maproulette-python-client.readthedocs.io/ |
| 4 | + |
| 5 | +This client makes it easy for users to communicate with the MapRoulette API from within |
| 6 | +their Python environment. In the example below, we are able to access a MapRoulette project in just four lines of code: |
| 7 | + |
| 8 | +``` |
| 9 | + >>> import maproulette |
| 10 | + >>> config = maproulette.Configuration() |
| 11 | + >>> api = maproulette.Project(config) |
| 12 | + >>> api.get_project_by_id(4719) |
| 13 | + {'data': {'id': 4719, 'owner': 4785024, 'name': 'health_facilities_in_india',...} |
| 14 | +``` |
| 15 | + |
| 16 | +The full documentation for this package can be found [here](https://maproulette-python-client.readthedocs.io/). |
| 17 | + |
| 18 | + |
| 19 | +## Getting Started |
| 20 | + |
| 21 | +Install the package (or add it to your requirements.txt file): |
| 22 | + |
| 23 | +```bash |
| 24 | +pip install maproulette |
| 25 | +``` |
| 26 | + |
| 27 | +Import the package: |
| 28 | + |
| 29 | +``` |
| 30 | +import maproulette |
| 31 | +``` |
| 32 | + |
| 33 | +From there, create a configuration object. Depending on your use case, you may need to pass your API key. Specify |
| 34 | +that when you create your configuration. For example: |
| 35 | + |
| 36 | +``` |
| 37 | +config = maproulette.Configuration(api_key='{YOUR_API_KEY}') |
| 38 | +``` |
| 39 | + |
| 40 | +Once you have your configuration object we can create an API object using one of several modules depending on the |
| 41 | +functionality that the user is looking for. For example, creating a Project object allows the user to interact with all |
| 42 | +of the project-related functionality in the MapRoulette package. |
| 43 | + |
| 44 | +``` |
| 45 | +api = maproulette.Project(config) |
| 46 | +``` |
| 47 | + |
| 48 | +Now we have access to the MapRoulette Project API methods. In the example below, I want to find a project by name using |
| 49 | +a search string: |
| 50 | + |
| 51 | +``` |
| 52 | +# We want to fetch a project with name 'Health Facilities in India' |
| 53 | +my_project_name = 'Health Facilities in India' |
| 54 | +
|
| 55 | +# Pretty-print the API response |
| 56 | +print(json.dumps(api.find_project(my_project_name), indent=4, sort_keys=True)) |
| 57 | +``` |
| 58 | + |
| 59 | +This returns a nicely printed JSON object representing the project named 'Health Facilities in India': |
| 60 | + |
| 61 | +``` |
| 62 | +{ |
| 63 | + "data": [ |
| 64 | + { |
| 65 | + "created": "2019-08-26T06:34:28.655Z", |
| 66 | + "deleted": false, |
| 67 | + "description": "Adding the Hospitals ", |
| 68 | + "displayName": "Health Facilities in India", |
| 69 | + "enabled": true, |
| 70 | + "featured": false, |
| 71 | + "groups": [ |
| 72 | + { |
| 73 | + "created": "2020-03-25T16:23:04.360Z", |
| 74 | + "groupType": 1, |
| 75 | + "id": 9273, |
| 76 | + "modified": "2020-03-25T16:23:04.360Z", |
| 77 | + "name": "4719_Admin", |
| 78 | + "projectId": 4719 |
| 79 | + }, |
| 80 | + { |
| 81 | + "created": "2020-03-25T16:23:04.360Z", |
| 82 | + "groupType": 2, |
| 83 | + "id": 9274, |
| 84 | + "modified": "2020-03-25T16:23:04.360Z", |
| 85 | + "name": "4719_Write", |
| 86 | + "projectId": 4719 |
| 87 | + }, |
| 88 | + { |
| 89 | + "created": "2020-03-25T16:23:04.360Z", |
| 90 | + "groupType": 3, |
| 91 | + "id": 9275, |
| 92 | + "modified": "2020-03-25T16:23:04.360Z", |
| 93 | + "name": "4719_Read", |
| 94 | + "projectId": 4719 |
| 95 | + } |
| 96 | + ], |
| 97 | + "id": 4719, |
| 98 | + "isVirtual": false, |
| 99 | + "modified": "2020-01-30T11:05:44.466Z", |
| 100 | + "name": "health_facilities_in_india", |
| 101 | + "owner": 4785024 |
| 102 | + } |
| 103 | + ], |
| 104 | + "status": 200 |
| 105 | +} |
| 106 | +``` |
| 107 | +## Development |
| 108 | + |
| 109 | +### Contributing |
| 110 | + |
| 111 | +Open an issue! Thanks for contributing! |
| 112 | + |
| 113 | +### Testing |
| 114 | + |
| 115 | +This package uses [Tox](https://tox.readthedocs.io/en/latest/) to perform testing. In order to run Tox, execute the |
| 116 | +`tox` command from the root directory. |
| 117 | + |
| 118 | + |
| 119 | +### Building the Documentation |
| 120 | + |
| 121 | +The documentation for this package is built with [Sphinx](https://www.sphinx-doc.org/en/master/index.html). In order to |
| 122 | +build the documentation for this package: |
| 123 | + |
| 124 | +``` |
| 125 | +$ cd docs |
| 126 | +``` |
| 127 | +and then: |
| 128 | +``` |
| 129 | +$ make html |
| 130 | +``` |
| 131 | +That command will generate the HTML documentation files for the project. We've hosted these docs at |
| 132 | +[Read the Docs](https://readthedocs.org/). |
0 commit comments