|
| 1 | +# Introduction |
| 2 | + |
| 3 | +## Motivation |
| 4 | + |
| 5 | +farmOS.py is a Python library for interacting with farmOS servers over API. |
| 6 | + |
| 7 | +This library was developed to support more custom use cases that interact |
| 8 | +with the farmOS server from a Python scripting environment. It can be used |
| 9 | +to build custom importers and exporters that interface with CSV, IoT and |
| 10 | +other APIs. farmOS.py also helps integrate with existing scientific and GIS |
| 11 | +tools that exist in the Python ecosystem. |
| 12 | + |
| 13 | +The [farmOS Aggregator](https://github.com/farmOS/farmOS-aggregator) |
| 14 | +also uses farmOS.py to communicate with farmOS servers. |
| 15 | + |
| 16 | +## Quick start |
| 17 | + |
| 18 | +Learn farmOS.py by example. |
| 19 | + |
| 20 | +### 1. Install |
| 21 | + |
| 22 | +To install using `pip`: |
| 23 | + |
| 24 | +```bash |
| 25 | +$ pip install farmOS~=1.0.0b |
| 26 | +``` |
| 27 | + |
| 28 | +To install using `conda` see [conda-forge/farmos-feedstock](https://github.com/conda-forge/farmos-feedstock#installing-farmos) |
| 29 | + |
| 30 | +### 2. Create a farm client instance |
| 31 | + |
| 32 | +```python |
| 33 | +from farmOS import farmOS |
| 34 | + |
| 35 | +farm_client = farmOS( |
| 36 | + hostname= "https://farm.example.com", |
| 37 | + client_id = "farm", |
| 38 | + scope = "farm_manager", |
| 39 | +) |
| 40 | +``` |
| 41 | + |
| 42 | +### 3. Authorize with farmOS server |
| 43 | + |
| 44 | +```python |
| 45 | +token = farm_client.authorize() |
| 46 | +# Complete username and password prompts. |
| 47 | +``` |
| 48 | + |
| 49 | +### 4. Get farmOS server info |
| 50 | + |
| 51 | +```python |
| 52 | +info = farm_client.info() |
| 53 | +``` |
| 54 | + |
| 55 | +### 5. CRUD Operations with a farmOS log |
| 56 | + |
| 57 | +```python |
| 58 | + |
| 59 | +# Create observation log |
| 60 | +observation_log = { |
| 61 | + "attributes": { |
| 62 | + "name": "My Great Observation", |
| 63 | + "status": "pending", |
| 64 | + "notes": "Some notes" |
| 65 | + } |
| 66 | +} |
| 67 | +log = farm_client.log.send('observation', observation_log) |
| 68 | +log_id = log["data"]["id"] |
| 69 | + |
| 70 | +# Update the log status to "done". |
| 71 | +done = { |
| 72 | + 'id': log_id, |
| 73 | + "attributes": { |
| 74 | + "status": "done", |
| 75 | + } |
| 76 | +} |
| 77 | +updated_log = farm_client.log.send('observation', done) |
| 78 | + |
| 79 | +# Delete the log. |
| 80 | +farm_client.log.delete('observation', log_id) |
| 81 | +``` |
| 82 | + |
| 83 | +## Next steps |
| 84 | + |
| 85 | +Now that you know the basics, dive deeper into following topics: |
| 86 | + |
| 87 | +- [Authorizing with farmOS server](authorization.md) |
| 88 | +- [Working with farmOS resources](client_2x.md) |
0 commit comments