Simple API client for numbersapi.com
- Supports major types like
trivia
,math
,date
,year
- Supports options
fragment
,notfound
,default
,Min & Max
- Minimum number of external dependencies
- requests
from numbersapi import NumbersApi
na = NumbersApi()
res = na.trivia(10)
>>> res.text
'10 is the number of hydrogen atoms in butane, a hydrocarbon.'
>>> res.number
'10'
>>> res.type
'trivia'
By default, result contains object with all attributes like text
, number
, type
etc.
You also can use print
or str
for more code simplification:
from numbersapi import NumbersApi
na = NumbersApi()
res = na.trivia(10)
>>> print(res)
'10 is the number of hydrogen atoms in butane, a hydrocarbon.'
Random date
from numbersapi import NumbersApi
na = NumbersApi()
res = na.date()
Default response option
from numbersapi import NumbersApi
na = NumbersApi(default="Too many units")
res = na.date(1111111111111111111111)
Covered by pytest
python -m pytest