how to use pyknackhq python library for getting whole objects/tables from my knack builder
Question:
I am trying to connect knack online database with my python data handling scripts in order to renew objects/tables directly into my knack app builder. I discovered pyknackhq Python API for KnackHQ can fetch objects and return json objects for the object’s records. So far so good.
However, following the documentation (http://www.wbh-doc.com.s3.amazonaws.com/pyknackhq/quick%20start.html) I have tried to fetch all rows (records in knack) for my object-table (having in total 344 records).
My code was:
i =0
for rec in undec_obj.find():
print(rec)
i=i+1
print(i)
>> 25
All first 25 records were returned indeed, however the rest until the 344-th were never returned. The documentation of pyknackhq library is relatively small so I couldn’t find a way around my problem there. Is there a solution to get all my records/rows? (I have also changed the specification in knack to have all my records appear in the same page – page 1).
The ultimate goal is to take all records and make them a pandas dataframe.
thank you!
Answers:
I haven’t worked with that library, but I’ve written another python Knack API wrapper that should help:
https://github.com/cityofaustin/knackpy
The docs should get you where you want to go. Here’s an example:
>>> from knackpy import Knack
# download data from knack object
# will fetch records in chunks of 1000 until all records have been downloaded
# optionally pass a rows_per_page and/or page_limit parameter to limit record count
>>> kn = Knack(
obj='object_3',
app_id='someappid',
api_key='topsecretapikey',
page_limit=10, # not needed; this is the default
rows_per_page=1000 # not needed; this is the default
)
>>> for row in kn.data:
print(row)
{'store_id': 30424, 'inspection_date': 1479448800000, 'id': '58598262bcb3437b51194040'},...
Hope that helps. Open a GitHub issue if you have any questions using the package.
Hey I am using your api and I have an issue with the filter. The filter isnt filtering the data. does your api support filters. I tried exactly the same thing the documentation shows but it isnt happeneing. This is what my filter looks like. Can you tell me if i made a mistake writing this filter.
filters = {
"rules": [
{"field": "field5","operator": "is", "value": "Closed"}
]
}
records = app.get("Project", record_limit=10, filters= filters)
Hey I am using your api and I have an issue with the filter. The filter isnt filtering the data. does your api support filters. I tried exactly the same thing the documentation shows but it isnt happeneing. This is what my filter looks like. Can you tell me if i made a mistake writing this filter.
filters = {
"rules": [
{"field": "field5","operator": "is", "value": "Closed"}
]
}
records = app.get("Project", record_limit=10, filters= filters)
I am trying to connect knack online database with my python data handling scripts in order to renew objects/tables directly into my knack app builder. I discovered pyknackhq Python API for KnackHQ can fetch objects and return json objects for the object’s records. So far so good.
However, following the documentation (http://www.wbh-doc.com.s3.amazonaws.com/pyknackhq/quick%20start.html) I have tried to fetch all rows (records in knack) for my object-table (having in total 344 records).
My code was:
i =0
for rec in undec_obj.find():
print(rec)
i=i+1
print(i)
>> 25
All first 25 records were returned indeed, however the rest until the 344-th were never returned. The documentation of pyknackhq library is relatively small so I couldn’t find a way around my problem there. Is there a solution to get all my records/rows? (I have also changed the specification in knack to have all my records appear in the same page – page 1).
The ultimate goal is to take all records and make them a pandas dataframe.
thank you!
I haven’t worked with that library, but I’ve written another python Knack API wrapper that should help:
https://github.com/cityofaustin/knackpy
The docs should get you where you want to go. Here’s an example:
>>> from knackpy import Knack
# download data from knack object
# will fetch records in chunks of 1000 until all records have been downloaded
# optionally pass a rows_per_page and/or page_limit parameter to limit record count
>>> kn = Knack(
obj='object_3',
app_id='someappid',
api_key='topsecretapikey',
page_limit=10, # not needed; this is the default
rows_per_page=1000 # not needed; this is the default
)
>>> for row in kn.data:
print(row)
{'store_id': 30424, 'inspection_date': 1479448800000, 'id': '58598262bcb3437b51194040'},...
Hope that helps. Open a GitHub issue if you have any questions using the package.
Hey I am using your api and I have an issue with the filter. The filter isnt filtering the data. does your api support filters. I tried exactly the same thing the documentation shows but it isnt happeneing. This is what my filter looks like. Can you tell me if i made a mistake writing this filter.
filters = {
"rules": [
{"field": "field5","operator": "is", "value": "Closed"}
]
}
records = app.get("Project", record_limit=10, filters= filters)
Hey I am using your api and I have an issue with the filter. The filter isnt filtering the data. does your api support filters. I tried exactly the same thing the documentation shows but it isnt happeneing. This is what my filter looks like. Can you tell me if i made a mistake writing this filter.
filters = {
"rules": [
{"field": "field5","operator": "is", "value": "Closed"}
]
}
records = app.get("Project", record_limit=10, filters= filters)