Skip to content

Add variable metadata#983

Closed
RamParameswaran wants to merge 9 commits into
masterfrom
add-variable-metadata
Closed

Add variable metadata#983
RamParameswaran wants to merge 9 commits into
masterfrom
add-variable-metadata

Conversation

@RamParameswaran

Copy link
Copy Markdown
Contributor

New features

  • Introduce metadata attribute to Variable class
    • metadata is a python dict
    • it accepts all basic types and can be nested to arbitrary depth
  • Adds metadata key to the web-api route "/variable/<id>"
    • converts dict to JSON and includes in Response

Use Case

  • Allows the addition of arbitrary structured metadata to OpenFisca variables
  • Allows retrieval of that structured metadata in the web-api
    • Can allow for presenting additional context-specific details in frontend applications, such as structured regulation references like these
    • Can allow for filtering/search in frontend applications ...

This feature is essentially an extension of the reference attribute, but allows for arbitrary dictionaries instead of just strings and lists of strings...

Example

Example of structured metadata:

class ABCD(Variable):
    ...
    metadata = {"regulation_reference": {"part": 5,
                                         "clause": "A",
                                         "schedule": "34b",
                                         "notes": ["foo", "bar"],
                                         },
                "is_output": True                        
                }

Example web-api Response for GET /variables/ABCD/:

{
  id: "ABCD",
    ...
  metadata:{"regulation_reference": {"part": 5,
                                     "clause": "A",
                                     "schedule": "34b",
                                     "notes": ["foo", "bar"],
                                      },
            "is_output": True                        
            }
}

Notes

  • Tests for the web_api Response are tightly coupled to the "openfisca_country_template" repo, so I've (for the moment) forgone testing for the web_api Response.
  • Failing tests are fixed by branch 'fix-doc-test-api'

@RamParameswaran

Copy link
Copy Markdown
Contributor Author

If #984 is accepted, I can add web_api tests as appropriate.

@Ndpnt Ndpnt closed this Nov 25, 2025
@Ndpnt Ndpnt force-pushed the add-variable-metadata branch from efcdeba to 08c5fa8 Compare November 25, 2025 21:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind:feat A feature request, a feature deprecation type:contrib Contribution from the community (PR)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Variables cannot have a metadata: dict attribute, unlike parameters

4 participants