records

SQL for Humans™

https://github.com/kennethreitz/records

Science Score: 23.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
  • DOI references
  • Academic publication links
  • Committers with academic emails
    2 of 50 committers (4.0%) from academic institutions
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (12.4%) to scientific vocabulary

Keywords

forhumans kennethreitz orm postgres python schemas sql sqlalchemy

Keywords from Contributors

packaging virtualenv pip pipfile human python-requests cookies requests notebook pallets
Last synced: 6 months ago · JSON representation

Repository

SQL for Humans™

Basic Info
Statistics
  • Stars: 7,215
  • Watchers: 185
  • Forks: 577
  • Open Issues: 44
  • Releases: 1
Topics
forhumans kennethreitz orm postgres python schemas sql sqlalchemy
Created about 11 years ago · Last pushed over 1 year ago
Metadata Files
Readme Changelog Funding License

README.md

Records: SQL for Humans™

image

Records is a very simple, but powerful, library for making raw SQL queries to most relational databases.

image

Just write SQL. No bells, no whistles. This common task can be surprisingly difficult with the standard tools available. This library strives to make this workflow as simple as possible, while providing an elegant interface to work with your query results.

Database support includes RedShift, Postgres, MySQL, SQLite, Oracle, and MS-SQL (drivers not included).

☤ The Basics

We know how to write SQL, so let's send some to our database:

``` python import records

db = records.Database('postgres://...') rows = db.query('select * from activeusers') # or db.queryfile('sqls/active-users.sql') ```

Grab one row at a time:

``` python

rows[0] ```

Or iterate over them:

python for r in rows: print(r.name, r.user_email)

Values can be accessed many ways: row.user_email, row['user_email'], or row[3].

Fields with non-alphanumeric characters (like spaces) are also fully supported.

Or store a copy of your record collection for later reference:

``` python

rows.all() [, , , ...] ```

If you're only expecting one result:

``` python

rows.first() ```

Other options include rows.as_dict() and rows.as_dict(ordered=True).

☤ Features

  • Iterated rows are cached for future reference.
  • $DATABASE_URL environment variable support.
  • Convenience Database.get_table_names method.
  • Command-line records tool for exporting queries.
  • Safe parameterization: Database.query('life=:everything', everything=42).
  • Queries can be passed as strings or filenames, parameters supported.
  • Transactions: t = Database.transaction(); t.commit().
  • Bulk actions: Database.bulk_query() & Database.bulk_query_file().

Records is proudly powered by SQLAlchemy and Tablib.

☤ Data Export Functionality

Records also features full Tablib integration, and allows you to export your results to CSV, XLS, JSON, HTML Tables, YAML, or Pandas DataFrames with a single line of code. Excellent for sharing data with friends, or generating reports.

``` pycon

print(rows.dataset) username|active|name |user_email |timezone --------|------|----------|-----------------|-------------------------- model-t |True |Henry Ford|model-t@gmail.com|2016-02-06 22:28:23.894202 ... ```

Comma Separated Values (CSV)

``` pycon

print(rows.export('csv')) username,active,name,user_email,timezone model-t,True,Henry Ford,model-t@gmail.com,2016-02-06 22:28:23.894202 ... ```

YAML Ain't Markup Language (YAML)

``` python

print(rows.export('yaml')) - {active: true, name: Henry Ford, timezone: '2016-02-06 22:28:23.894202', user_email: model-t@gmail.com, username: model-t} ... ```

JavaScript Object Notation (JSON)

``` python

print(rows.export('json')) [{"username": "model-t", "active": true, "name": "Henry Ford", "user_email": "model-t@gmail.com", "timezone": "2016-02-06 22:28:23.894202"}, ...] ```

Microsoft Excel (xls, xlsx)

python with open('report.xls', 'wb') as f: f.write(rows.export('xls'))

Pandas DataFrame

``` python

rows.export('df') username active name user_email timezone 0 model-t True Henry Ford model-t@gmail.com 2016-02-06 22:28:23.894202 ```

You get the point. All other features of Tablib are also available, so you can sort results, add/remove columns/rows, remove duplicates, transpose the table, add separators, slice data by column, and more.

See the Tablib Documentation for more details.

☤ Installation

Of course, the recommended installation method is pipenv:

$ pipenv install records[pandas]
✨🍰✨

☤ Thank You

Thanks for checking this library out! I hope you find it useful.

Of course, there's always room for improvement. Feel free to open an issue so we can make Records better, stronger, faster.


Star History Chart

Owner

  • Name: Kenneth Reitz
  • Login: kennethreitz
  • Kind: user
  • Location: Virginia, USA, Earth, Milky Way.

Software Engineer focused on abstractions, reducing cognitive overhead, and Design for Humans.

GitHub Events

Total
  • Issues event: 3
  • Watch event: 96
  • Issue comment event: 5
  • Pull request event: 1
  • Pull request review comment event: 1
  • Pull request review event: 2
  • Fork event: 16
Last Year
  • Issues event: 3
  • Watch event: 96
  • Issue comment event: 5
  • Pull request event: 1
  • Pull request review comment event: 1
  • Pull request review event: 2
  • Fork event: 16

Committers

Last synced: 9 months ago

All Time
  • Total Commits: 301
  • Total Committers: 50
  • Avg Commits per committer: 6.02
  • Development Distribution Score (DDS): 0.329
Past Year
  • Commits: 1
  • Committers: 1
  • Avg Commits per committer: 1.0
  • Development Distribution Score (DDS): 0.0
Top Committers
Name Email Commits
Kenneth Reitz me@k****g 202
Jan Vlcinsky j****y@t****m 15
Chad Whitacre c****d@z****m 11
Harold Cooper h****r@g****m 6
mcdallas m****s@h****m 6
Brobin t****n@g****m 3
Greg Troszak g****k@g****m 3
Joakim Uddholm t****k@g****m 3
prasad83 p****3 2
Waldir Pimenta w****s@g****m 2
Nikhil Murthy n****y@g****m 2
Hugo h****k 2
Frazer McLean f****r@f****k 2
Daniel Schep d****p@g****m 2
Brian Hammond b****n@f****m 2
Andrew Doroschenko a****n@y****u 2
Kenneth Reitz k****z@K****l 2
arokosaki a****i 2
wanpeng w****g@g****v 1
TomFaulkner T****m@t****m 1
Paul Philip Voelker p****r@c****e 1
Alan King k****j@u****m 1
Andrew Murray r****e@g****m 1
Beha s****p@m****m 1
Brent Tubbs b****s@g****m 1
restran g****n@g****m 1
fritz-clicktripz f****z@c****m 1
dependabot[bot] 4****] 1
WangWeigao w****o@g****m 1
Varun Agrawal v****l@g****m 1
and 20 more...

Issues and Pull Requests

Last synced: 6 months ago

All Time
  • Total issues: 82
  • Total pull requests: 27
  • Average time to close issues: 10 months
  • Average time to close pull requests: over 3 years
  • Total issue authors: 71
  • Total pull request authors: 25
  • Average comments per issue: 2.78
  • Average comments per pull request: 1.04
  • Merged pull requests: 15
  • Bot issues: 0
  • Bot pull requests: 3
Past Year
  • Issues: 4
  • Pull requests: 2
  • Average time to close issues: 6 days
  • Average time to close pull requests: N/A
  • Issue authors: 4
  • Pull request authors: 2
  • Average comments per issue: 0.75
  • Average comments per pull request: 1.0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • leafonsword (4)
  • hrldcpr (3)
  • chadwhitacre (3)
  • bfmcneill (2)
  • vlcinsky (2)
  • mcdallas (2)
  • zhonghai9967 (2)
  • laith43d (1)
  • sri-rang (1)
  • ragne (1)
  • emirot (1)
  • schlsj (1)
  • tspivey (1)
  • aklaver (1)
  • Imran-imtiaz48 (1)
Pull Request Authors
  • dependabot[bot] (4)
  • jraper3 (2)
  • arokosaki (2)
  • Imran-imtiaz48 (2)
  • shacknetisp (2)
  • paulvoe (2)
  • takhogan (2)
  • jdonboch (2)
  • kingaj12 (2)
  • keelanfh (2)
  • kipyin (2)
  • bfmcneill (2)
  • NaelsonDouglas (2)
  • prasad83 (2)
  • mkai (2)
Top Labels
Issue Labels
bug (12) enhancement (9) wontfix (5) question (4) moreinfo-needed (3) invalid (3) docs (3) help wanted (1) dependencies (1)
Pull Request Labels
dependencies (4)

Packages

  • Total packages: 4
  • Total downloads:
    • pypi 266,904 last-month
  • Total docker downloads: 79
  • Total dependent packages: 11
    (may contain duplicates)
  • Total dependent repositories: 256
    (may contain duplicates)
  • Total versions: 29
  • Total maintainers: 3
pypi.org: records

SQL for Humans

  • Versions: 13
  • Dependent Packages: 11
  • Dependent Repositories: 254
  • Downloads: 266,894 Last month
  • Docker Downloads: 79
Rankings
Stargazers count: 0.3%
Downloads: 0.7%
Dependent repos count: 0.9%
Dependent packages count: 0.9%
Average: 1.3%
Forks count: 2.1%
Docker downloads count: 2.6%
Maintainers (2)
Last synced: 6 months ago
proxy.golang.org: github.com/kennethreitz/records
  • Versions: 12
  • Dependent Packages: 0
  • Dependent Repositories: 1
Rankings
Stargazers count: 0.8%
Forks count: 1.2%
Average: 3.8%
Dependent repos count: 4.8%
Dependent packages count: 8.5%
Last synced: 6 months ago
pypi.org: records-csp

SQL for Humans

  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Downloads: 10 Last month
Rankings
Stargazers count: 0.3%
Forks count: 2.1%
Dependent packages count: 6.6%
Average: 17.9%
Dependent repos count: 30.6%
Downloads: 49.9%
Maintainers (1)
Last synced: 6 months ago
conda-forge.org: records
  • Versions: 3
  • Dependent Packages: 0
  • Dependent Repositories: 1
Rankings
Stargazers count: 3.7%
Forks count: 6.8%
Average: 21.5%
Dependent repos count: 24.1%
Dependent packages count: 51.5%
Last synced: 6 months ago