Skip to content

Add get_by_id to EdFiEndpoint#57

Open
ea-mtenhoor wants to merge 1 commit intomainfrom
feature/get-by-id
Open

Add get_by_id to EdFiEndpoint#57
ea-mtenhoor wants to merge 1 commit intomainfrom
feature/get-by-id

Conversation

@ea-mtenhoor
Copy link
Copy Markdown
Contributor

This PR adds a get_by_id method to EdFiEndpoint, allowing the retrieval of a single resource record by its Ed-Fi ID. A similar result is already possible by passing a dictionary with id to the params of get_rows. There is no practical performance improvement with either method, but there are some differences.

  • GET with params ends up making two calls to the Ed-Fi API.
    /data/v3/ed-fi/schools?id=44cbdc9355c74afe90262493a2aba769 and
    /data/v3/ed-fi/schools?id=44cbdc9355c74afe90262493a2aba769&pageToken=LTIxNDc0ODM2MzgsMjE0NzQ4MzY0Nw&pageSize=100
  • GET with params generates a SQL statement with unnecessary where clauses, including limit and offset.
  • GET with params returns a list with (probably) one object
  • GET with params is more code on the implementer side
  • GET by ID makes a single call.
    /data/v3/ed-fi/schools/44cbdc9355c74afe90262493a2aba769
  • GET by ID only has one SQL query parameter, the ID.
  • GET by ID returns a single dictionary.
  • GET by ID is less code on the implementer side
schools = edfi_api.resource('schools')
get_params = list(schools.get_rows(params={'id': '44cbdc9355c74afe90262493a2aba769'}))[0]
get_by_id  = schools.get_by_id('44cbdc9355c74afe90262493a2aba769')

@ea-mtenhoor ea-mtenhoor requested a review from jayckaiser April 20, 2026 22:10
logger.info(f"[Get by id {self.component}] Endpoint: {url}")

params = EdFiParams(params or self.params).copy()
logger.info(f"[Get by id {self.component}] Parameters: {params}")
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are there any params that are relevant to include when querying by ID directly? If not, I would want to omit these from being used to avoid the possibility of someone passing mutually-exclusive arguments and parameters (e.g., different IDs, etc.).

params = EdFiParams(params or self.params).copy()
logger.info(f"[Get by id {self.component}] Parameters: {params}")

return self.client.session.get_response(url, params=params, **kwargs).json()
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To confirm, if the ID passed is undefined, will this return an empty dictionary?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants