{"id":13481565,"url":"https://github.com/kennethreitz/records","last_synced_at":"2025-12-17T21:16:07.542Z","repository":{"id":25033022,"uuid":"28452637","full_name":"kennethreitz/records","owner":"kennethreitz","description":"SQL for Humans™","archived":false,"fork":false,"pushed_at":"2024-07-09T11:26:43.000Z","size":313,"stargazers_count":7192,"open_issues_count":43,"forks_count":574,"subscribers_count":185,"default_branch":"master","last_synced_at":"2025-05-04T05:02:43.919Z","etag":null,"topics":["forhumans","kennethreitz","orm","postgres","python","schemas","sql","sqlalchemy"],"latest_commit_sha":null,"homepage":"https://pypi.python.org/pypi/records/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"isc","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kennethreitz.png","metadata":{"files":{"readme":"README.md","changelog":"HISTORY.rst","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":"kennethreitz"}},"created_at":"2014-12-24T15:20:23.000Z","updated_at":"2025-05-03T16:55:14.000Z","dependencies_parsed_at":"2022-07-14T09:22:34.035Z","dependency_job_id":"8b3c877e-0d77-49c0-9473-52f8d0f4c8c0","html_url":"https://github.com/kennethreitz/records","commit_stats":{"total_commits":301,"total_committers":50,"mean_commits":6.02,"dds":0.3289036544850499,"last_synced_commit":"5941ab2798cb91455b6424a9564c9cd680475fbe"},"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kennethreitz%2Frecords","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kennethreitz%2Frecords/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kennethreitz%2Frecords/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kennethreitz%2Frecords/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kennethreitz","download_url":"https://codeload.github.com/kennethreitz/records/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253745198,"owners_count":21957319,"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":["forhumans","kennethreitz","orm","postgres","python","schemas","sql","sqlalchemy"],"created_at":"2024-07-31T17:00:52.863Z","updated_at":"2025-12-17T21:16:07.475Z","avatar_url":"https://github.com/kennethreitz.png","language":"Python","funding_links":["https://github.com/sponsors/kennethreitz"],"categories":["Python","python","Database Clients","Database Tools","Recursos para el manejo de bases de datos","Linux生态圈Dev\u0026Ops工具与服务"],"sub_categories":["Learning Resources","Otras bibliotecas útiles"],"readme":"# Records: SQL for Humans™\n\n[![image](https://img.shields.io/pypi/v/records.svg)](https://pypi.python.org/pypi/records)\n\n**Records is a very simple, but powerful, library for making raw SQL\nqueries to most relational databases.**\n\n![image](https://farm1.staticflickr.com/569/33085227621_7e8da49b90_k_d.jpg)\n\nJust write SQL. No bells, no whistles. This common task can be\nsurprisingly difficult with the standard tools available. This library\nstrives to make this workflow as simple as possible, while providing an\nelegant interface to work with your query results.\n\n*Database support includes RedShift, Postgres, MySQL, SQLite, Oracle,\nand MS-SQL (drivers not included).*\n\n## ☤ The Basics\n\nWe know how to write SQL, so let's send some to our database:\n\n``` python\nimport records\n\ndb = records.Database('postgres://...')\nrows = db.query('select * from active_users')    # or db.query_file('sqls/active-users.sql')\n```\n\nGrab one row at a time:\n\n``` python\n\u003e\u003e\u003e rows[0]\n\u003cRecord {\"username\": \"model-t\", \"active\": true, \"name\": \"Henry Ford\", \"user_email\": \"model-t@gmail.com\", \"timezone\": \"2016-02-06 22:28:23.894202\"}\u003e\n```\n\nOr iterate over them:\n\n``` python\nfor r in rows:\n    print(r.name, r.user_email)\n```\n\nValues can be accessed many ways: `row.user_email`, `row['user_email']`,\nor `row[3]`.\n\nFields with non-alphanumeric characters (like spaces) are also fully\nsupported.\n\nOr store a copy of your record collection for later reference:\n\n``` python\n\u003e\u003e\u003e rows.all()\n[\u003cRecord {\"username\": ...}\u003e, \u003cRecord {\"username\": ...}\u003e, \u003cRecord {\"username\": ...}\u003e, ...]\n```\n\nIf you're only expecting one result:\n\n``` python\n\u003e\u003e\u003e rows.first()\n\u003cRecord {\"username\": ...}\u003e\n```\n\nOther options include `rows.as_dict()` and `rows.as_dict(ordered=True)`.\n\n## ☤ Features\n\n-   Iterated rows are cached for future reference.\n-   `$DATABASE_URL` environment variable support.\n-   Convenience `Database.get_table_names` method.\n-   Command-line \u003cspan class=\"title-ref\"\u003erecords\u003c/span\u003e tool for\n    exporting queries.\n-   Safe parameterization:\n    `Database.query('life=:everything', everything=42)`.\n-   Queries can be passed as strings or filenames, parameters supported.\n-   Transactions: `t = Database.transaction(); t.commit()`.\n-   Bulk actions: `Database.bulk_query()` \u0026\n    `Database.bulk_query_file()`.\n\nRecords is proudly powered by [SQLAlchemy](http://www.sqlalchemy.org)\nand [Tablib](https://tablib.readthedocs.io/en/latest/).\n\n## ☤ Data Export Functionality\n\nRecords also features full Tablib integration, and allows you to export\nyour results to CSV, XLS, JSON, HTML Tables, YAML, or Pandas DataFrames\nwith a single line of code. Excellent for sharing data with friends, or\ngenerating reports.\n\n``` pycon\n\u003e\u003e\u003e print(rows.dataset)\nusername|active|name      |user_email       |timezone\n--------|------|----------|-----------------|--------------------------\nmodel-t |True  |Henry Ford|model-t@gmail.com|2016-02-06 22:28:23.894202\n...\n```\n\n**Comma Separated Values (CSV)**\n\n``` pycon\n\u003e\u003e\u003e print(rows.export('csv'))\nusername,active,name,user_email,timezone\nmodel-t,True,Henry Ford,model-t@gmail.com,2016-02-06 22:28:23.894202\n...\n```\n\n**YAML Ain't Markup Language (YAML)**\n\n``` python\n\u003e\u003e\u003e print(rows.export('yaml'))\n- {active: true, name: Henry Ford, timezone: '2016-02-06 22:28:23.894202', user_email: model-t@gmail.com, username: model-t}\n...\n```\n\n**JavaScript Object Notation (JSON)**\n\n``` python\n\u003e\u003e\u003e print(rows.export('json'))\n[{\"username\": \"model-t\", \"active\": true, \"name\": \"Henry Ford\", \"user_email\": \"model-t@gmail.com\", \"timezone\": \"2016-02-06 22:28:23.894202\"}, ...]\n```\n\n**Microsoft Excel (xls, xlsx)**\n\n``` python\nwith open('report.xls', 'wb') as f:\n    f.write(rows.export('xls'))\n```\n\n**Pandas DataFrame**\n\n``` python\n\u003e\u003e\u003e rows.export('df')\n    username  active       name        user_email                   timezone\n0    model-t    True Henry Ford model-t@gmail.com 2016-02-06 22:28:23.894202\n```\n\nYou get the point. All other features of Tablib are also available, so\nyou can sort results, add/remove columns/rows, remove duplicates,\ntranspose the table, add separators, slice data by column, and more.\n\nSee the [Tablib Documentation](https://tablib.readthedocs.io/) for more\ndetails.\n\n## ☤ Installation\n\nOf course, the recommended installation method is\n[pipenv](http://pipenv.org):\n\n    $ pipenv install records[pandas]\n    ✨🍰✨\n\n## ☤ Thank You\n\nThanks for checking this library out! I hope you find it useful.\n\nOf course, there's always room for improvement. Feel free to [open an\nissue](https://github.com/kennethreitz/records/issues) so we can make\nRecords better, stronger, faster.\n\n--------------\n\n[![Star History Chart](https://api.star-history.com/svg?repos=kennethreitz/records\u0026type=Date)](https://star-history.com/#kennethreitz/records\u0026Date)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkennethreitz%2Frecords","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkennethreitz%2Frecords","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkennethreitz%2Frecords/lists"}