{"id":15003388,"url":"https://github.com/pypyodbc/pypyodbc","last_synced_at":"2025-04-09T10:08:38.287Z","repository":{"id":39623457,"uuid":"344382949","full_name":"pypyodbc/pypyodbc","owner":"pypyodbc","description":"pypyodbc is a pure Python cross platform ODBC interface module (pyodbc compatible as of 2017)","archived":false,"fork":false,"pushed_at":"2023-12-14T23:14:15.000Z","size":248,"stargazers_count":57,"open_issues_count":17,"forks_count":19,"subscribers_count":5,"default_branch":"main","last_synced_at":"2025-04-02T08:06:38.119Z","etag":null,"topics":["database","odbc","odbcsql","python","sql","sql-server","sqlserver"],"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/pypyodbc.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"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":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-03-04T07:11:12.000Z","updated_at":"2025-03-19T11:42:58.000Z","dependencies_parsed_at":"2024-06-18T18:25:58.701Z","dependency_job_id":"17d15b64-541d-44f0-9dc2-c2408a74ac2c","html_url":"https://github.com/pypyodbc/pypyodbc","commit_stats":{"total_commits":167,"total_committers":32,"mean_commits":5.21875,"dds":"0.31137724550898205","last_synced_commit":"e1b29992baaea09f951669d2c2167b1820b208ef"},"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pypyodbc%2Fpypyodbc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pypyodbc%2Fpypyodbc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pypyodbc%2Fpypyodbc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pypyodbc%2Fpypyodbc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pypyodbc","download_url":"https://codeload.github.com/pypyodbc/pypyodbc/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248018060,"owners_count":21034048,"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":["database","odbc","odbcsql","python","sql","sql-server","sqlserver"],"created_at":"2024-09-24T18:58:15.081Z","updated_at":"2025-04-09T10:08:38.264Z","avatar_url":"https://github.com/pypyodbc.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"pypyodbc\n========\n\nA pure Python Cross Platform ODBC interface module\n\n\n**This is the new GitHub homepage of pypyodbc**  \n\nOld repository was https://github.com/jiangwen365/pypyodbc/\n\nAlso check out the [Wiki](https://github.com/pypyodbc/pypyodbc/wiki) and [Version History](https://github.com/pypyodbc/pypyodbc/wiki/Version-History)\n\n\nFeatures\n--------\n\n  * One pure Python script, runs on CPython / IronPython / PyPy , Python 3.3 / 2.4 / 2.5 / 2.6 / 2.7 , Win / Linux / macOS, 32 / 64 bit: [How to use pypyodbc on MacOS OSX](https://github.com/pypyodbc/pypyodbc/wiki/How-to-use-pypyodbc-on-MacOS-OSX)\n  * Almost totally same usage as pyodbc (can be seen as a re-implementation of pyodbc in pure Python via ctypes)\n  * Simple - the whole module is implemented in a single python script with less than 3000 lines\n  * [Built-in Access MDB file creation and compression functions](https://github.com/pypyodbc/pypyodbc/wiki/Access-MDB-support) on Windows \n\nSimply try pypyodbc:\n\n```python\n# Microsoft Access DB\nimport pypyodbc \n\nconnection = pypyodbc.win_create_mdb('D:\\\\database.mdb')\n\nSQL = 'CREATE TABLE saleout (id COUNTER PRIMARY KEY,product_name VARCHAR(25));'\nconnection.cursor().execute(SQL)\nconnection.close()\n```\n\n```python\n#SQL Server 2000/2005/2008 (and probably 2012 and 2014)\nimport pypyodbc as pyodbc # you could alias it to existing pyodbc code (not every code is compatible)\ndb_host = 'serverhost'\ndb_name = 'database'\ndb_user = 'username'\ndb_password = 'password'\nconnection_string = 'Driver={SQL Server};Server=' + db_host + ';Database=' + db_name + ';UID=' + db_user + ';PWD=' + db_password + ';'\ndb = pyodbc.connect(connection_string)\nSQL = 'CREATE TABLE saleout (id COUNTER PRIMARY KEY,product_name VARCHAR(25));'\ndb.cursor().execute(SQL)\n\n# Doing a simple SELECT query\nconnStr = (\n    r'Driver={SQL Server};'\n    r'Server=sqlserver;'\n    #r'Server=127.0.0.1,52865;' +\n    #r'Server=(local)\\SQLEXPRESS;'\n    r'Database=adventureworks;'\n    #r'Trusted_Connection=Yes;'\n    r'UID=sa;'\n    r'PWD=sapassword;'\n    )\ndb = pypyodbc.connect(connStr)\ncursor = db.cursor()\n\n# Sample with just a raw query:\ncursor.execute(\"select client_name, client_lastname, [phone number] from Clients where client_id like '01-01-00%'\")\n\n# Using parameters (IMPORTANT: YOU SHOULD USE TUPLE TO PASS PARAMETERS)\n# Python note: a tuple with just one element must have a trailing comma, otherwise is just a enclosed variable\ncursor.execute(\"select client_name, client_lastname, [phone number] \"\n\"from Clients where client_id like ?\", ('01-01-00%', ))\n\n# Sample, passing more than one parameter\ncursor.execute(\"select client_name, client_lastname, [phone number] \"\n\"from Clients where client_id like ? and client_age \u003c ?\", ('01-01-00%', 28))\n\n# Method 1, simple reading using cursor\nwhile True:\n    row = cursor.fetchone()\n    if not row:\n        break\n    print(\"Client Full Name (phone number): \", row['client_name'] + ' ' +  row['client_lastname'] + '(' + row['phone number'] + ')')\n\n# Method 2, we obtain dict's all records are loaded at the same time in memory (easy and verbose, but just use it with a few records or your app will consume a lot of memory), was tested in a modern computer with about 1000 - 3000 records just fine...\nimport pprint; pp = pprint.PrettyPrinter(indent=4)\ncolumns = [column[0] for column in cursor.description]\nfor row in cursor.fetchall():\n    pp.pprint(dict(zip(columns, row)))\n\n# Method 3, we obtain a list of dict's (represents the entire query)\nquery_results = [dict(zip([column[0] for column in cursor.description], row)) for row in cursor.fetchall()]\npp.pprint(query_results)\n\n# When cursor was used must be closed, if you will not use again the db connection must be closed too.\ncursor.close()\ndb.close()\n```\n\nHow to use it without install (the latest version from here)\n--------------------------------------------\nJust copy the latest pypyodbc.py downloaded from this repository on your project folder and import the module.\n\nInstall\n-------\n\nIf you have pip available (keep in mind that the version on pypi may be old):\n\n    pip install pypyodbc\n\nOr get the latest pypyodbc.py script from GitHub (Main Development site) \u003chttps://github.com/pypyodbc/pypyodbc\u003e\n\n    python setup.py install\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpypyodbc%2Fpypyodbc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpypyodbc%2Fpypyodbc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpypyodbc%2Fpypyodbc/lists"}