Getting Started
Installation
The library is available on PyPi and can be installed using pip:
1pip install pyforks
API Key
To use the Trailforks API you will need to obtain an API key. The top right of the Trailforks API page has instructions on how to obtain an API key.
Usage
There are a few things to understand about the REST API and therefore the PyForks library. Most importantly, how function parameters work. The sections below will cover these topics.
Function Parameters
Each function allows for **kwargs
given the Trailforks API allows for a wide range of parameters. The parameters are passed as keyword arguments to the function. As such, it will be very common to define a dictionary of parameters and pass it to the function. For example:
1from PyForks import Regions
2
3region_api = Regions(app_id='your_app_id', app_secret='your_app_secret')
4params = {'filter': 'rid::12345'}
5region_api.get_region(**params)
Some functions have required parameters. These are defined in the function signature. Trailforks has not defined many of the parameters and filters that could be used, so it is up to the user to ensure the correct parameters are passed based on the limited documentation both on the Trailforks website as well as within these docs. However, for required parameters, the function signature will define them as well.
I’ve also taken some time to add each REST API and therefore each PyForks function to a swagger.json file:
Enums
Trailforks has many different Enums that are used by the API to define specific values. All Enums are defined in the lookups
module as dictionaries. Each dictionary is based off of the offical Trailforks documentation metadata. For example:
1trail_conditions = {
2 0: "Unknown",
3 1: "Snow Packed",
4 2: "Prevalent Mud",
5 3: "Wet",
6 4: "Variable",
7 5: "Dry",
8 6: "Very Dry",
9 7: "Snow Covered",
10 8: "Freeze/thaw Cycle",
11 9: "Icy",
12 10: "Snow Groomed",
13 11: "Ideal",
14 12: "Snow Cover Partial"
15}
16
17difficulty_short = {
18 1: "Access Road/Trail",
19 2: "White",
20 3: "Green",
21 4: "Blue",
22 5: "Black",
23 6: "Double Black Diamond",
24 7: "Secondary Access Road/Trail",
25 8: "Proline",
26 12: "Lift"
27}