{"id":17635943,"url":"https://github.com/mohawk2/sqlalchemy-csv-normalise","last_synced_at":"2025-03-30T03:43:07.986Z","repository":{"id":46059450,"uuid":"236528769","full_name":"mohawk2/sqlalchemy-csv-normalise","owner":"mohawk2","description":"SQLAlchemy utilities for normalising / denormalising table data, useful for CSV","archived":false,"fork":false,"pushed_at":"2023-11-02T21:25:39.000Z","size":24,"stargazers_count":1,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-05T06:14:22.747Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/mohawk2.png","metadata":{"files":{"readme":"README.rst","changelog":"HISTORY.rst","contributing":"CONTRIBUTING.rst","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":"AUTHORS.rst","dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-01-27T15:55:53.000Z","updated_at":"2021-11-17T00:41:47.000Z","dependencies_parsed_at":"2025-01-08T20:32:52.607Z","dependency_job_id":null,"html_url":"https://github.com/mohawk2/sqlalchemy-csv-normalise","commit_stats":{"total_commits":8,"total_committers":2,"mean_commits":4.0,"dds":0.25,"last_synced_commit":"a18f734653f6e99b856934ef2e78c58b198c7602"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mohawk2%2Fsqlalchemy-csv-normalise","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mohawk2%2Fsqlalchemy-csv-normalise/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mohawk2%2Fsqlalchemy-csv-normalise/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mohawk2%2Fsqlalchemy-csv-normalise/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mohawk2","download_url":"https://codeload.github.com/mohawk2/sqlalchemy-csv-normalise/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246273515,"owners_count":20750904,"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":[],"created_at":"2024-10-23T02:24:44.705Z","updated_at":"2025-03-30T03:43:07.970Z","avatar_url":"https://github.com/mohawk2.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"========================\nsqlalchemy-csv-normalise\n========================\n\n\n.. image:: https://img.shields.io/pypi/v/sqlalchemy-csv-normalise.svg\n        :target: https://pypi.python.org/pypi/sqlalchemy-csv-normalise\n\n.. image:: https://travis-ci.com/mohawk2/sqlalchemy-csv-normalise.svg?branch=master\n        :target: https://travis-ci.com/mohawk2/sqlalchemy-csv-normalise\n\n.. image:: https://readthedocs.org/projects/sqlalchemy-csv-normalise/badge/?version=latest\n        :target: https://sqlalchemy-csv-normalise.readthedocs.io/en/latest/?badge=latest\n        :alt: Documentation Status\n\n\n.. image:: https://pyup.io/repos/github/mohawk2/sqlalchemy-csv-normalise/shield.svg\n     :target: https://pyup.io/repos/github/mohawk2/sqlalchemy-csv-normalise/\n     :alt: Updates\n\n\n\nSQLAlchemy utilities for normalising / denormalising table data, useful for CSV\n\n\nWhere a table is normalised to have \"lookup tables\" of values\nreferred to by e.g. a numeric foreign-key ID, these functions will\nenable extraction of the data (or conversely, loading from such)\nwith the looked-up values substituted in. Among other things, this\nallows more human-friendly data editing in e.g. a spreadsheet.\n\nExample::\n\n    from sqlalchemy_csv_normalise import denormalise_prepare\n    q, col_names = denormalise_prepare(db.session, table)\n    filename = table_to_filename(table)\n    with open(filename, 'w', newline='') as csv_file:\n        csv_file_writer = csv.writer(csv_file)\n        csv_file_writer.writerow(col_names)\n        csv_file_writer.writerows(q.all())\n\n    from sqlalchemy_csv_normalise import renormalise_prepare, empty_deleter,\\\n        type_coercer\n    row_maker = renormalise_prepare(db.session, table)\n    row_cleaner = empty_deleter(table)\n    row_coercer = type_coercer(table)\n    filename = table_to_filename(table)\n    with open(filename, newline='') as csv_file:\n        for d in csv.DictReader(csv_file):\n            row = row_coercer(row_cleaner(row_maker(d)))\n            db.session.add(table(**row))\n    db.session.commit()\n\n\n* Free software: MIT license\n* Documentation: https://sqlalchemy-csv-normalise.readthedocs.io.\n\n\nFeatures\n--------\n\n* denormalise_prepare(session, table, colname_tidier)\n\nReturns SQLAlchemy query, and the column-names it will return.\nThe query will denormalise any foreign keys (FKs) if they refer to a\ntable with a unique column that is not its primary key.\n\nThe names of any FK columns will have `_id` taken off the end\nas a simple heuristic. Override this by providing a `colname_tidier`.\n\n\n* empty_deleter(table)\n\nReturns function that returns given dict minus empty strings for nullable\ncolumns.\nUseful because CSV has no way to record NULL.\n\n* type_coercer(table)\n\nReturns function that given a row dict will coerce values.\nWorks on dates and booleans.\nWill only operate on strings, so if you have pass in a row that has already\ngot non-string values, they will not be affected.\n\n* renormalise_prepare(session, table, colname_tidier)\n\nReturns function that will renormalise given dictionary\nDoes the inverse of denormalise_prepare.\n\nCredits\n-------\n\nThis package was created with Cookiecutter_ and the `audreyr/cookiecutter-pypackage`_ project template.\n\n.. _Cookiecutter: https://github.com/audreyr/cookiecutter\n.. _`audreyr/cookiecutter-pypackage`: https://github.com/audreyr/cookiecutter-pypackage\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmohawk2%2Fsqlalchemy-csv-normalise","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmohawk2%2Fsqlalchemy-csv-normalise","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmohawk2%2Fsqlalchemy-csv-normalise/lists"}