{"id":14976209,"url":"https://github.com/dapalex/py-graphql-mapper","last_synced_at":"2025-07-15T10:04:25.733Z","repository":{"id":61003075,"uuid":"544354751","full_name":"dapalex/py-graphql-mapper","owner":"dapalex","description":"A python library for generating GraphQL queries and mutations using plain python objects, no hardcoded strings.Any questions or issues, please report here https://github.com/dapalex/py-graphql-mapper/issues ","archived":false,"fork":false,"pushed_at":"2023-08-14T19:56:23.000Z","size":3767,"stargazers_count":22,"open_issues_count":2,"forks_count":2,"subscribers_count":1,"default_branch":"develop","last_synced_at":"2025-06-29T19:15:24.594Z","etag":null,"topics":["graphql","graphql-python","mapping","python","python-graphql","python-graphql-client","python3"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dapalex.png","metadata":{"files":{"readme":"README.MD","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"dapalex"}},"created_at":"2022-10-02T09:09:25.000Z","updated_at":"2025-03-13T21:48:28.000Z","dependencies_parsed_at":"2024-09-18T19:02:08.603Z","dependency_job_id":null,"html_url":"https://github.com/dapalex/py-graphql-mapper","commit_stats":{"total_commits":158,"total_committers":2,"mean_commits":79.0,"dds":"0.44303797468354433","last_synced_commit":"d5d63f2193d06dd9bdeae615cf51c8382247bf66"},"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/dapalex/py-graphql-mapper","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dapalex%2Fpy-graphql-mapper","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dapalex%2Fpy-graphql-mapper/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dapalex%2Fpy-graphql-mapper/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dapalex%2Fpy-graphql-mapper/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dapalex","download_url":"https://codeload.github.com/dapalex/py-graphql-mapper/tar.gz/refs/heads/develop","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dapalex%2Fpy-graphql-mapper/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265426961,"owners_count":23763190,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["graphql","graphql-python","mapping","python","python-graphql","python-graphql-client","python3"],"created_at":"2024-09-24T13:53:30.723Z","updated_at":"2025-07-15T10:04:25.666Z","avatar_url":"https://github.com/dapalex.png","language":"Python","funding_links":["https://github.com/sponsors/dapalex","https://github.com/sponsors/dapalex?frequency=one-time\u0026sponsor=dapalex"],"categories":[],"sub_categories":[],"readme":"[![Python package](https://github.com/dapalex/py-graphql-mapper/actions/workflows/python-package.yml/badge.svg)](https://github.com/dapalex/py-graphql-mapper/actions/workflows/python-package.yml)\n[![Codacy Badge](https://app.codacy.com/project/badge/Grade/280533e425784f7da9ecb0f6e529886b)](https://www.codacy.com/gh/dapalex/py-graphql-mapper/dashboard?utm_source=github.com\u0026amp;utm_medium=referral\u0026amp;utm_content=dapalex/py-graphql-mapper\u0026amp;utm_campaign=Badge_Grade)\n--------------------------------------------------------------------------------\n# py-graphql-mapper\n[![Code Generation Test](https://github.com/dapalex/py-graphql-mapper/actions/workflows/test-codegen.yml/badge.svg)](https://github.com/dapalex/py-graphql-mapper/actions/workflows/test-codegen.yml)\n[![Pyhon-GraphQL Mapping Test](https://github.com/dapalex/py-graphql-mapper/actions/workflows/test-map.yml/badge.svg)](https://github.com/dapalex/py-graphql-mapper/actions/workflows/test-map.yml)\n\nA python library to interact with GraphQL APIs with no need of hardcoded strings.\n\n## Introduction\n\nThis library acts as a mapper between python and GraphQL languages for GraphQL clients, allowing a code-first approach when calling a GraphQL API server.\nIt translates GraphQL entities into python objects and viceversa in order to avoid working with massive \"copy\u0026paste\"s.\n\nThis document contains a quick overview of the functionalities, for more details and options you can read here:\n\n* [Code Generation](https://github.com/dapalex/py-graphql-mapper/blob/develop/codegen/README.MD)\n* [Core Mapper](https://github.com/dapalex/py-graphql-mapper/blob/develop/pygqlmap/README.MD)\n* [Use Cases](https://github.com/dapalex/py-graphql-mapper/blob/develop/tests/README.MD)\n\n\nThe package does not use any third-party libraries, it relies only on python 3 (3.10+) standard libraries.\n\n\n## Usage in a nutshell\n\n### Installation\n\nAvailable in PyPI, the following command will install the library:\n\n```\npip install py-graphql-mapper\n```\n\n\n### Generate python code from schema\n\nTo generate the code execute the following command:\n\n```\npgmcodegen generate ./pathToOutputFolder -apiArgs ./\u003cpathToArgsFile\u003e/generatorArgs.json\n```\n\nThis command requires a json file containing the parameters needed to get the GraphQL schema\n\n![image](https://github.com/dapalex/py-graphql-mapper/blob/develop/docs/cli_args_nutshell.png)\n\nA sample is available in the main folder ['cli_args.json'](https://github.com/dapalex/py-graphql-mapper/blob/develop/cli_args.json).\n\nThe following python files will be generated:\n\n* enums.py\n* scalars.py\n* gql_simple_types.py\n* gql_types.py\n* type_refs.py\n* queries.py\n* mutations.py\n\nThese links show code generated using the library [Github GraphQL API](https://github.com/dapalex/py-graphql-mapper/blob/develop/tests/output/github), [Rapid GraphQL API](https://github.com/dapalex/py-graphql-mapper/blob/develop/tests/output/rapidapi) and [GeoDBCities API](https://github.com/dapalex/py-graphql-mapper/blob/develop/tests/output/gdbc)\n\nMore command options are available [here](https://github.com/dapalex/py-graphql-mapper/blob/develop/codegen/README.MD#usage-via-command-line)\n\n\n### Execution of a query\n\nChoose the query class you want to use from the generated file queries.py (or a mutation from mutations.py):\n\nInstantiate it adding GraphQL arguments if needed:\n```python\nfrom .output.gdbc.queries import currencies\n\nmy_currencies = currencies(last=7, before='MTE=')\n```\nor add them using the field _args_\n\n```python\nmy_currencies._args.last = 7\nmy_currencies._args.before = 'MTE='\n```\nThen call _export_gql_source_ property to pass the payload to the HTTP request:\n\n(example using _requests_ library)\n```python\nimport requests\n\nresponse = requests.request('POST', url='https://geodb-cities-graphql.p.rapidapi.com/',\n                            json= { \"query\": my_currencies.export_gql_source },\n                            headers={\n                                    \"content-type\": \"application/json\",\n                                        \"X-RapidAPI-Key\": '123402mmri02fni230iif32jr420',\n                                        \"X-RapidAPI-Host\": \"geodb-cities-graphql.p.rapidapi.com\"\n                                    }\n                            )\n```\n\nMore details on how to set a query [here](https://github.com/dapalex/py-graphql-mapper/blob/develop/pygqlmap/README.MD#creation-of-an-operation)\n\n\n### Retrieval of a response\n\nObtained the response from the GraphQL API the following code will map the received json payload into the python object\n\n```python\nfrom pygqlmap.network import GQLResponse\n\ngqlResponse = GQLResponse(response)\n\ngqlResponse.map_gqldata_to_obj(myCurrenciesQuery.type)\n\nprint('Result object: ' + str(gqlResponse.result_obj))\n```\n\nThe mapped response from the GraphQL server will be available within _gqlResponse_ object: `_gqlResponse.result_obj_`\n\nMore details [here](https://github.com/dapalex/py-graphql-mapper/blob/develop/pygqlmap/README.MD#parsing-of-a-response)\n\n\nA suite of use cases [here](https://github.com/dapalex/py-graphql-mapper/blob/develop/tests/README.MD)\n\n[![\"Buy Me A Coffee\"](https://www.buymeacoffee.com/assets/img/custom_images/orange_img.png)](https://github.com/sponsors/dapalex?frequency=one-time\u0026sponsor=dapalex)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdapalex%2Fpy-graphql-mapper","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdapalex%2Fpy-graphql-mapper","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdapalex%2Fpy-graphql-mapper/lists"}