Python Forum
Changing client.get() method type based on size of data...
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Changing client.get() method type based on size of data...
#1
How do I convert the following code to use the offset limit items and get a large item instead of doing a get_all type operation? The code I want to convert is below. There seems to be a way of paginating the download of the data but then creating the DataFrame at the end and just using that instead of going through the records thing you see below:
            client = Socrata(nmdx_url, token, username, password, timeout=90)

            item_count += 1

            # Process metadata
            ds_md = client.get_metadata(ds)
            print('=[ ' + str(item_count) + ' ]==================================================================================================================')
            print(f"ID: {ds_md['id']}")
            print(f"NAME: {ds_md['name']}")
            print(f"CATEGORY: {ds_md['category']}")
            print(f"DESCRIPTION: {ds_md['description']}")
            #print(f"rowsUpdatedAt: {ds_md['rowsUpdatedAt']} ({datetime.fromtimestamp(ds_md['rowsUpdatedAt'])})")

            # Fetch records from the table
            ds_md = client.get_metadata(ds)
            ds_cols = [colname['fieldName'] for colname in ds_md['columns']]
            ds_records = client.get(ds, where='', limit=10)
            #ds_records = client.get_all(ds, where='')
            #ds_records = client.get_all(ds)
            ds_df = pd.DataFrame.from_records(ds_records, columns=ds_cols)
How do you do this without the ds_records thing here and I resolve cols?

Something like:
            chunk = client.get(limit=chunk_size, offset=offset)

            if not chunk:  # Check for empty response
                break

            all_data.extend(chunk)
            offset += chunk_size
Again, I'm trying to do the client.get() where the get happens many times with limited data to keep the network traffic reasonable. How is this done?

Thanks
Yoriz write Jan-02-2025, 09:21 PM:
Please post all code, output and errors (in its entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Reply
#2
Basically, when I do the get with the "get all" type, the system crashes from time to time. With smaller downloads it doesn't seem to do that!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Python class members based on a type value voidtrance 7 1,237 Apr-11-2025, 10:10 PM
Last Post: deanhystad
  client A to server B connects but client B to server A doesnt connect gerald 1 778 Aug-17-2024, 07:33 AM
Last Post: Gribouillis
  A question on Boolean Data Type Hudjefa 5 1,195 Aug-13-2024, 11:03 AM
Last Post: Hudjefa
  Is changing processes by using match with type function impossible? cametan 1 721 May-30-2024, 02:16 PM
Last Post: cametan
  Grouping Data based on 30% bracket purnima1 4 2,142 Mar-10-2023, 07:38 PM
Last Post: deanhystad
  i want to use type= as a function/method keyword argument Skaperen 9 3,605 Nov-06-2022, 04:28 AM
Last Post: Skaperen
  conditionals based on data frame mbrown009 1 1,570 Aug-12-2022, 08:18 AM
Last Post: Larz60+
  Issue in changing data format (2 bytes) into a 16 bit data. GiggsB 11 5,005 Jul-25-2022, 03:19 PM
Last Post: deanhystad
  I have written a program that outputs data based on GPS signal kalle 1 2,061 Jul-22-2022, 12:10 AM
Last Post: mcmxl22
  Setup host for consistent data transfer to client via TCP Gustav97 0 1,339 Jun-27-2022, 07:33 PM
Last Post: Gustav97

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020