Skip to content

Commit abd00af

Browse files
authored
multi: fix links/format (#56)
1 parent ead8f79 commit abd00af

1 file changed

Lines changed: 73 additions & 52 deletions

File tree

docs/usage.md

Lines changed: 73 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,83 @@
11
# Usage
2+
23
To use Pokepy in a project:
4+
35
```python
46
>>> import pokepy
57
```
68

79
### API
8-
Pokepy is composed of a single class, `V2Client`, which implements the whole
9-
[v2 PokéAPI](https://pokeapi.co/docs/v2.html).
10+
11+
Pokepy is composed of a single class, `V2Client`, which implements the whole
12+
[v2 PokéAPI](https://pokeapi.co/docs/v2).
1013
This class is usually instantiated without parameters:
14+
1115
```python
1216
>>> client = pokepy.V2Client()
1317
```
18+
1419
Unless you want to use the caching feature, which is discussed [further below](#cache).
1520

1621
Each endpoint of PokéAPI is represented in `V2Client` by a `get_<endpoint_name>` method,
1722
all taking a single parameter (`uid`), which can be either an `integer` (for most endpoints) or a `string`.
1823

1924
The following is an exhaustive list of all the endpoints with links to their respective PokéAPI documentation:
2025

21-
* [get_berry](https://pokeapi.co/docs/v2.html/#berries)
22-
* [get_berry_firmness](https://pokeapi.co/docs/v2.html/#berry-firmnesses)
23-
* [get_berry_flavor](https://pokeapi.co/docs/v2.html/#berry-flavors)
24-
* [get_contest_type](https://pokeapi.co/docs/v2.html/#contest-types)
25-
* [get_contest_effect](https://pokeapi.co/docs/v2.html/#contest-effects)
26-
* [get_super_contest_effect](https://pokeapi.co/docs/v2.html/#super-contest-effects)
27-
* [get_encounter_method](https://pokeapi.co/docs/v2.html/#encounter-methods)
28-
* [get_encounter_condition](https://pokeapi.co/docs/v2.html/#encounter-conditions)
29-
* [get_encounter_condition_value](https://pokeapi.co/docs/v2.html/#encounter-condition-values)
30-
* [get_evolution_chain](https://pokeapi.co/docs/v2.html/#evolution-chains)
31-
* [get_evolution_trigger](https://pokeapi.co/docs/v2.html/#evolution-triggers)
32-
* [get_generation](https://pokeapi.co/docs/v2.html/#generations)
33-
* [get_pokedex](https://pokeapi.co/docs/v2.html/#pokedexes)
34-
* [get_version](https://pokeapi.co/docs/v2.html/#version)
35-
* [get_version_group](https://pokeapi.co/docs/v2.html/#version-groups)
36-
* [get_item](https://pokeapi.co/docs/v2.html/#item)
37-
* [get_item_attribute](https://pokeapi.co/docs/v2.html/#item-attributes)
38-
* [get_item_category](https://pokeapi.co/docs/v2.html/#item-categories)
39-
* [get_item_fling_effect](https://pokeapi.co/docs/v2.html/#item-fling-effects)
40-
* [get_item_pocket](https://pokeapi.co/docs/v2.html/#item-pockets)
41-
* [get_location](https://pokeapi.co/docs/v2.html/#locations)
42-
* [get_location_area](https://pokeapi.co/docs/v2.html/#location-areas)
43-
* [get_pal_park_area](https://pokeapi.co/docs/v2.html/#pal-park-areas)
44-
* [get_region](https://pokeapi.co/docs/v2.html/#regions)
45-
* [get_machine](https://pokeapi.co/docs/v2.html/#machines)
46-
* [get_move](https://pokeapi.co/docs/v2.html/#moves)
47-
* [get_move_ailment](https://pokeapi.co/docs/v2.html/#move-ailments)
48-
* [get_move_battle_style](https://pokeapi.co/docs/v2.html/#move-battle-styles)
49-
* [get_move_category](https://pokeapi.co/docs/v2.html/#move-categories)
50-
* [get_move_damage_class](https://pokeapi.co/docs/v2.html/#move-damage-classes)
51-
* [get_move_learn_method](https://pokeapi.co/docs/v2.html/#move-learn-methods)
52-
* [get_move_target](https://pokeapi.co/docs/v2.html/#move-targets)
53-
* [get_ability](https://pokeapi.co/docs/v2.html/#abilities)
54-
* [get_characteristic](https://pokeapi.co/docs/v2.html/#characteristics)
55-
* [get_egg_group](https://pokeapi.co/docs/v2.html/#egg-groups)
56-
* [get_gender](https://pokeapi.co/docs/v2.html/#genders)
57-
* [get_growth_rate](https://pokeapi.co/docs/v2.html/#growth-rates)
58-
* [get_nature](https://pokeapi.co/docs/v2.html/#natures)
59-
* [get_pokeathlon_stat](https://pokeapi.co/docs/v2.html/#pokeathlon-stats)
60-
* [get_pokemon](https://pokeapi.co/docs/v2.html/#pokemon)
61-
* [get_pokemon_color](https://pokeapi.co/docs/v2.html/#pok%C3%A9mon-colors)
62-
* [get_pokemon_form](https://pokeapi.co/docs/v2.html/#pok%C3%A9mon-forms)
63-
* [get_pokemon_habitat](https://pokeapi.co/docs/v2.html/#pok%C3%A9mon-habitats)
64-
* [get_pokemon_shape](https://pokeapi.co/docs/v2.html/#pok%C3%A9mon-shapes)
65-
* [get_pokemon_species](https://pokeapi.co/docs/v2.html/#pok%C3%A9mon-species)
66-
* [get_stat](https://pokeapi.co/docs/v2.html/#stats)
67-
* [get_type](https://pokeapi.co/docs/v2.html/#types)
68-
* [get_language](https://pokeapi.co/docs/v2.html/#languages)
26+
- [get_berry](https://pokeapi.co/docs/v2#berries)
27+
- [get_berry_firmness](https://pokeapi.co/docs/v2#berry-firmnesses)
28+
- [get_berry_flavor](https://pokeapi.co/docs/v2#berry-flavors)
29+
- [get_contest_type](https://pokeapi.co/docs/v2#contest-types)
30+
- [get_contest_effect](https://pokeapi.co/docs/v2#contest-effects)
31+
- [get_super_contest_effect](https://pokeapi.co/docs/v2#super-contest-effects)
32+
- [get_encounter_method](https://pokeapi.co/docs/v2#encounter-methods)
33+
- [get_encounter_condition](https://pokeapi.co/docs/v2#encounter-conditions)
34+
- [get_encounter_condition_value](https://pokeapi.co/docs/v2#encounter-condition-values)
35+
- [get_evolution_chain](https://pokeapi.co/docs/v2#evolution-chains)
36+
- [get_evolution_trigger](https://pokeapi.co/docs/v2#evolution-triggers)
37+
- [get_generation](https://pokeapi.co/docs/v2#generations)
38+
- [get_pokedex](https://pokeapi.co/docs/v2#pokedexes)
39+
- [get_version](https://pokeapi.co/docs/v2#version)
40+
- [get_version_group](https://pokeapi.co/docs/v2#version-groups)
41+
- [get_item](https://pokeapi.co/docs/v2#item)
42+
- [get_item_attribute](https://pokeapi.co/docs/v2#item-attributes)
43+
- [get_item_category](https://pokeapi.co/docs/v2#item-categories)
44+
- [get_item_fling_effect](https://pokeapi.co/docs/v2#item-fling-effects)
45+
- [get_item_pocket](https://pokeapi.co/docs/v2#item-pockets)
46+
- [get_location](https://pokeapi.co/docs/v2#locations)
47+
- [get_location_area](https://pokeapi.co/docs/v2#location-areas)
48+
- [get_pal_park_area](https://pokeapi.co/docs/v2#pal-park-areas)
49+
- [get_region](https://pokeapi.co/docs/v2#regions)
50+
- [get_machine](https://pokeapi.co/docs/v2#machines)
51+
- [get_move](https://pokeapi.co/docs/v2#moves)
52+
- [get_move_ailment](https://pokeapi.co/docs/v2#move-ailments)
53+
- [get_move_battle_style](https://pokeapi.co/docs/v2#move-battle-styles)
54+
- [get_move_category](https://pokeapi.co/docs/v2#move-categories)
55+
- [get_move_damage_class](https://pokeapi.co/docs/v2#move-damage-classes)
56+
- [get_move_learn_method](https://pokeapi.co/docs/v2#move-learn-methods)
57+
- [get_move_target](https://pokeapi.co/docs/v2#move-targets)
58+
- [get_ability](https://pokeapi.co/docs/v2#abilities)
59+
- [get_characteristic](https://pokeapi.co/docs/v2#characteristics)
60+
- [get_egg_group](https://pokeapi.co/docs/v2#egg-groups)
61+
- [get_gender](https://pokeapi.co/docs/v2#genders)
62+
- [get_growth_rate](https://pokeapi.co/docs/v2#growth-rates)
63+
- [get_nature](https://pokeapi.co/docs/v2#natures)
64+
- [get_pokeathlon_stat](https://pokeapi.co/docs/v2#pokeathlon-stats)
65+
- [get_pokemon](https://pokeapi.co/docs/v2#pokemon)
66+
- [get_pokemon_color](https://pokeapi.co/docs/v2#pok%C3%A9mon-colors)
67+
- [get_pokemon_form](https://pokeapi.co/docs/v2#pok%C3%A9mon-forms)
68+
- [get_pokemon_habitat](https://pokeapi.co/docs/v2#pok%C3%A9mon-habitats)
69+
- [get_pokemon_shape](https://pokeapi.co/docs/v2#pok%C3%A9mon-shapes)
70+
- [get_pokemon_species](https://pokeapi.co/docs/v2#pok%C3%A9mon-species)
71+
- [get_stat](https://pokeapi.co/docs/v2#stats)
72+
- [get_type](https://pokeapi.co/docs/v2#types)
73+
- [get_language](https://pokeapi.co/docs/v2#languages)
6974

7075
Each method returns an object containing as many python attributes as there are named attributes.
71-
Please refer to the [PokéAPI documentation](https://pokeapi.co/docs/v2.html/)
76+
Please refer to the [PokéAPI documentation](https://pokeapi.co/docs/v2)
7277
for more information on what each of these methods returns, its description and type.
7378

7479
Then you can start grabbing stuff from the API:
80+
7581
```python
7682
>>> mew = pokepy.V2Client().get_pokemon('mew')
7783
>>> mew
@@ -117,7 +123,9 @@ Prevents sleep.
117123
```
118124

119125
### Parameters
126+
120127
Most resources can be requested by using either the `name` or `id` of the resource:
128+
121129
```python
122130
>>> pokepy.V2Client().get_pokemon('rotom')
123131
<Pokemon - Rotom>
@@ -128,13 +136,16 @@ Most resources can be requested by using either the `name` or `id` of the resour
128136
```
129137

130138
### Cache
139+
131140
If you use the API to get the same resources often,
132141
you can enable cache to avoid making unnecessary requests to the PokéAPI server.
133142
You can either enable `memory-based` or `disk-based` cache.
134143

135144
#### Memory-based
145+
136146
Memory-based cache is activated by passing `in_memory` to the `cache` parameter of `V2Client`.
137147
Resources obtained from the PokéAPI are then saved in RAM. Cache is kept per get method:
148+
138149
```python
139150
>>> client_mem_cache = pokepy.V2Client(cache='in_memory')
140151
```
@@ -143,13 +154,15 @@ You can check the state of the cache in two ways: per get method or as a whole.
143154

144155
To check the state of the cache of a particular method, call the `cache_info()`
145156
of that get method:
157+
146158
```python
147159
>>> client_mem_cache.get_pokemon.cache_info()
148160
CacheInfo(hits=0, misses=0, size=0)
149161
```
150162

151163
To check the state of the cache as a whole (all get methods combined),
152164
call the `cache_info()` of `V2Client`:
165+
153166
```python
154167
>>> client_mem_cache.cache_info()
155168
CacheInfo(hits=0, misses=0, size=0)
@@ -160,6 +173,7 @@ CacheInfo(hits=0, misses=0, size=0)
160173
and `size` is the total number of cached parameters.
161174

162175
When calling a certain endpoint, the `cache_info` reflects that call:
176+
163177
```python
164178
>>> kakuna = client_mem_cache.get_pokemon(14)
165179
>>> client_mem_cache.get_pokemon.cache_info()
@@ -168,29 +182,34 @@ CacheInfo(hits=0, misses=1, size=1)
168182

169183
Calling the same resource as before with the same parameters will retrieve
170184
the cached resource instead of getting it from the server:
185+
171186
```python
172187
>>> kakuna = client_mem_cache.get_pokemon(14)
173188
>>> client_mem_cache.get_pokemon.cache_info()
174189
CacheInfo(hits=1, misses=1, size=1)
175190
```
176191

177192
To clear the cache of a specific get method:
193+
178194
```python
179195
>>> client_mem_cache.get_pokemon.cache_clear()
180196
>>> client_mem_cache.get_pokemon.cache_info()
181197
CacheInfo(hits=0, misses=0, size=0)
182198
```
183199

184200
To clear all cache:
201+
185202
```python
186203
>>> client_mem_cache.cache_clear()
187204
>>> client_mem_cache.cache_info()
188205
CacheInfo(hits=0, misses=0, size=0)
189206
```
190207

191208
#### Disk-based
209+
192210
Disk-based cache is activated by passing `in_disk` to the `cache` parameter of `V2Client`.
193211
Resources obtained from the PokéAPI are then saved to disk. Cache is kept per get method:
212+
194213
```python
195214
>>> client_disk_cache = pokepy.V2Client(cache='in_disk', cache_location='/temp')
196215
```
@@ -200,17 +219,19 @@ A folder named `pokepy_cache` will be created inside the specified directory, wh
200219
cache of each get method will be located.
201220
If no cache directory is specified a system-appropriate cache directory is automatically determined by
202221
[appdirs](https://pypi.org/project/appdirs/).
203-
222+
204223
The methods used to check the state and clear the cache are the same as in the memory-based cache,
205224
including the global `V2Client` methods.
206225

207226
You can also check the cache directory, per get method:
227+
208228
```python
209229
>>> client_disk_cache.get_pokemon.cache_location()
210230
/temp/pokepy_cache/39/cache
211231
```
212232

213233
Or check the global cache directory:
234+
214235
```python
215236
>>> client_disk_cache.cache_location()
216237
/temp/pokepy_cache/

0 commit comments

Comments
 (0)