forked from semolex/novaposhta-python-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREADME
70 lines (55 loc) · 2.76 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# novaposhta-api-client
Python client for Nova Poshta company's API.
## Installation
Client is based on `python 3.6`.
You can install package by using pip:
`pip install git+https://github.com/semolex/novaposhta-api-client`
## Description
Client is based on models and signatures, provided in [NovaPoshta API documentation](https://devcenter.novaposhta.ua/docs/services/).
Main idea of the client is to provide same methods as described there with minimal
changes when it possible.
Methods and they parameters in most cases shares same names as in API docs, but
in python-like style.
However, some models are omitted due to their singleton nature, for example,
`AddressGeneral` model is part of the `AddressModel`, because it has only one
method and semantically it is definitely part of the address-related items, etc.
You can explore source code to find this parts.
Also, while there methods are designed to wrap same methods from API, there is
may be some different and additions.
For example, some methods may be divided into
smaller logical parts, because they uses _a lot_ of parameters, also there is
additional classes (`WarehouseFilter` and `ExpressWaybill`), used to divide
some properties as separate class that can be passed to the method that will
extract required parts.
There is a plans to add more logical chunks, so user can have different ways of
manipulating complex parts.
## Usage
To start using client, you need to have API key.
Methods returns `requests.Response` object so you have ability to add different
checks and conversions, eg. check status codes, describe errors, warnings, etc.
Simple usage example:
```python
from novaposhta import NovaPoshtaApi
# call api by using corresponding models
client = NovaPoshtaApi(api_key='your-api-key')
areas = client.address.get_areas() # models can be accessed as client properties
print(areas.json())
# call api by using `send` method from client.
reasons = client.send('AdditionalService', 'getReturnReasons', {})
print(reasons.json())
# you can pass parameters into method using two different ways.
# 1. Pass them directly.
cities_one = client.address.search_settlements(city_name='Здолбунів', limit=5)
# 2. Prepare required object as dictionary and unpack it.
query = {
'city_name': 'Здолбунів',
'limit': 5
}
cities_two = client.address.search_settlements(**query)
```
## Plans to add before release version:
* Add name mappings, so user can pass JSON object with same property names as in API docs.
(eg. `AddressCity` can be used in dict object and then automatically converted into `address_city`)
* Create test parts
* Double check existing parameters, because API docs missing some small parts.
* Add more classes that can represent data chunks so it will be possible to manipulate big objects easily.