😸

Pythonパッケージのライセンス情報をCSVに出力する

2022/06/28に公開

目的

Pythonパッケージの以下の情報をCSVに出力する方法を検討する

  • パッケージ名
  • バージョン
  • ホームページ
  • ライセンス

実験環境

  • MacOS
  • python3.9

パッケージ一覧の取得方法

pipコマンドでインストールしたパッケージの一覧は下記のファイルで取得可能

pip list

https://pip.pypa.io/en/stable/cli/pip_list/

ライセンス情報は出力されない模様

パッケージの詳細情報の取得方法

pip showコマンドで個別のパッケージの詳細情報を表示できる。

%pip show requests
Name: requests
Version: 2.26.0
Summary: Python HTTP for Humans.
Home-page: https://requests.readthedocs.io
Author: Kenneth Reitz
Author-email: me@kennethreitz.org
License: Apache 2.0
Location: /usr/local/lib/python3.9/site-packages
Requires: certifi, charset-normalizer, idna, urllib3
Required-by: bert-score, folium, gdown, google-api-core, googlemaps, huggingface-hub, jupyterlab-server, pystac-client, transformers

https://pip.pypa.io/en/stable/cli/pip_show/

ライセンス情報は出力されるが、パッケージを個別に指定する必要がある

pypiに登録されている情報をJSONで取得する方法

pypiに登録されている情報は以下の形式でJSON形式として取得できる。

https://pypi.org/pypi/パッケージ名/バージョン/json

例: awslogs 0.14.0の情報

https://pypi.org/pypi/awslogs/0.14.0/json

jsonの内容
{
	"info": {
		"author": "Jorge Bastida",
		"author_email": "me@jorgebastida.com",
		"bugtrack_url": null,
		"classifiers": [
			"Development Status :: 4 - Beta",
			"Environment :: Web Environment",
			"Intended Audience :: Developers",
			"License :: OSI Approved :: BSD License",
			"Operating System :: OS Independent",
			"Programming Language :: Python :: 3",
			"Programming Language :: Python :: 3.5",
			"Programming Language :: Python :: 3.6",
			"Programming Language :: Python :: 3.7",
			"Programming Language :: Python :: 3.8",
			"Topic :: Utilities"
		],
		"description": "awslogs is a simple command line tool to read aws cloudwatch logs.\n\n\n",
		"description_content_type": "",
		"docs_url": null,
		"download_url": "",
		"downloads": {
			"last_day": -1,
			"last_month": -1,
			"last_week": -1
		},
		"home_page": "https://github.com/jorgebastida/awslogs",
		"keywords": "aws logs cloudwatch",
		"license": "BSD",
		"maintainer": "",
		"maintainer_email": "",
		"name": "awslogs",
		"package_url": "https://pypi.org/project/awslogs/",
		"platform": "any",
		"project_url": "https://pypi.org/project/awslogs/",
		"project_urls": {
			"Homepage": "https://github.com/jorgebastida/awslogs"
		},
		"release_url": "https://pypi.org/project/awslogs/0.14.0/",
		"requires_dist": [
			"boto3 (>=1.5.0)",
			"jmespath (<1.0.0,>=0.7.1)",
			"termcolor (>=1.1.0)",
			"python-dateutil (>=2.4.0)"
		],
		"requires_python": ">=3.5.*",
		"summary": "awslogs is a simple command line tool to read aws cloudwatch logs.",
		"version": "0.14.0",
		"yanked": false,
		"yanked_reason": null
	},
	"last_serial": 7672661,
	"releases": {
		"0.0.1": [
			{
				"comment_text": "",
				"digests": {
					"md5": "57b9f7f2e20dfae86cf7b2fafaa226b8",
					"sha256": "7215680ff12c819027095a2af1673a6d57846688d99204fb4b553660ea1b8ab7"
				},
				"downloads": -1,
				"filename": "awslogs-0.0.1.tar.gz",
				"has_sig": false,
				"md5_digest": "57b9f7f2e20dfae86cf7b2fafaa226b8",
				"packagetype": "sdist",
				"python_version": "source",
				"requires_python": null,
				"size": 7008,
				"upload_time": "2015-05-17T22:04:24",
				"upload_time_iso_8601": "2015-05-17T22:04:24.797764Z",
				"url": "https://files.pythonhosted.org/packages/04/5c/0d5eb84ed0316357e02d6b5d66b6870b265c2579fc059b7d7c09cacd7ccb/awslogs-0.0.1.tar.gz",
				"yanked": false,
				"yanked_reason": null
			}
		],
		"0.0.2": [
			{
				"comment_text": "",
				"digests": {
					"md5": "49af9490fe58d26739332f6e876623af",
					"sha256": "7788d4b48cb98bc8bf11e2be29417aa56826b476e13d24c76d533063f5895af7"
				},
				"downloads": -1,
				"filename": "awslogs-0.0.2.tar.gz",
				"has_sig": false,
				"md5_digest": "49af9490fe58d26739332f6e876623af",
				"packagetype": "sdist",
				"python_version": "source",
				"requires_python": null,
				"size": 11605,
				"upload_time": "2015-05-25T21:16:07",
				"upload_time_iso_8601": "2015-05-25T21:16:07.114910Z",
				"url": "https://files.pythonhosted.org/packages/b5/51/b3f5d73ec26567946d6f78567e48a0df2c202eee77d5cc0c4e6f4b286263/awslogs-0.0.2.tar.gz",
				"yanked": false,
				"yanked_reason": null
			}
		],
		"0.1.0": [
			{
				"comment_text": "",
				"digests": {
					"md5": "2d9a90e69fc41be114c7fd5dc35929b9",
					"sha256": "3cf7b480602c95eb3ac1615aca15d1517364603154a320eb6e4c0363ab4f10ad"
				},
				"downloads": -1,
				"filename": "awslogs-0.1.0.tar.gz",
				"has_sig": false,
				"md5_digest": "2d9a90e69fc41be114c7fd5dc35929b9",
				"packagetype": "sdist",
				"python_version": "source",
				"requires_python": null,
				"size": 10436,
				"upload_time": "2015-10-10T14:35:34",
				"upload_time_iso_8601": "2015-10-10T14:35:34.411681Z",
				"url": "https://files.pythonhosted.org/packages/46/b6/e1769b8dc7935404f8f872dc3df9c4562a8eedcc642154be4ac53c02f8b0/awslogs-0.1.0.tar.gz",
				"yanked": false,
				"yanked_reason": null
			}
		],
		"0.1.1": [
			{
				"comment_text": "",
				"digests": {
					"md5": "d2f52e57aa0f01f520e711307e9a57c8",
					"sha256": "f6ff49f8aa9ef38690bd989b05f21c2acaeeace8e7e0cd5a6970a5ee2b9ec52d"
				},
				"downloads": -1,
				"filename": "awslogs-0.1.1.tar.gz",
				"has_sig": false,
				"md5_digest": "d2f52e57aa0f01f520e711307e9a57c8",
				"packagetype": "sdist",
				"python_version": "source",
				"requires_python": null,
				"size": 10409,
				"upload_time": "2015-10-29T21:51:33",
				"upload_time_iso_8601": "2015-10-29T21:51:33.688149Z",
				"url": "https://files.pythonhosted.org/packages/3e/91/75c6f7bda11f6a8c37e7ed081b94a4e48d2848a1867a8af5b080e67f3627/awslogs-0.1.1.tar.gz",
				"yanked": false,
				"yanked_reason": null
			}
		],
		"0.1.2": [
			{
				"comment_text": "",
				"digests": {
					"md5": "ab8f661ec7fb0160b820d302893f73f2",
					"sha256": "9d66c055a1a00f18bf259aa6e951b95b11e42d579cdcc7f98cfd128f35a366d4"
				},
				"downloads": -1,
				"filename": "awslogs-0.1.2.tar.gz",
				"has_sig": false,
				"md5_digest": "ab8f661ec7fb0160b820d302893f73f2",
				"packagetype": "sdist",
				"python_version": "source",
				"requires_python": null,
				"size": 10656,
				"upload_time": "2015-11-03T18:35:35",
				"upload_time_iso_8601": "2015-11-03T18:35:35.543229Z",
				"url": "https://files.pythonhosted.org/packages/76/d0/2d889974f11a339deadabfcc3299e05271ebcbda01e5189d00403d8ace0e/awslogs-0.1.2.tar.gz",
				"yanked": false,
				"yanked_reason": null
			}
		],
		"0.10.0": [
			{
				"comment_text": "",
				"digests": {
					"md5": "1d101e59789b53c269126ed6ad132527",
					"sha256": "242c45806a7086cc20b9f8461e7b989d51ccf918e65d0c2c904b4f07b5f3c63a"
				},
				"downloads": -1,
				"filename": "awslogs-0.10.0-py2.py3-none-any.whl",
				"has_sig": false,
				"md5_digest": "1d101e59789b53c269126ed6ad132527",
				"packagetype": "bdist_wheel",
				"python_version": "2.7",
				"requires_python": null,
				"size": 9406,
				"upload_time": "2017-07-29T16:48:11",
				"upload_time_iso_8601": "2017-07-29T16:48:11.897150Z",
				"url": "https://files.pythonhosted.org/packages/fa/be/1552365a8ab39a11caea8ad3c8c42e37b2bc4cc8f50708cada5118757478/awslogs-0.10.0-py2.py3-none-any.whl",
				"yanked": false,
				"yanked_reason": null
			}
		],
		"0.11.0": [
			{
				"comment_text": "",
				"digests": {
					"md5": "cb545143ac48f3c838172314b78e7a06",
					"sha256": "274beaafcfa977c992eb53d22a2275a58a83b5c8e74516762ac085f7cd2f2a01"
				},
				"downloads": -1,
				"filename": "awslogs-0.11.0-py2.py3-none-any.whl",
				"has_sig": false,
				"md5_digest": "cb545143ac48f3c838172314b78e7a06",
				"packagetype": "bdist_wheel",
				"python_version": "py2.py3",
				"requires_python": null,
				"size": 9939,
				"upload_time": "2018-12-02T13:36:07",
				"upload_time_iso_8601": "2018-12-02T13:36:07.647239Z",
				"url": "https://files.pythonhosted.org/packages/45/be/28fe3276045c564aeb79fc74ba436201ded4a17d964d8be54adb72a0c873/awslogs-0.11.0-py2.py3-none-any.whl",
				"yanked": false,
				"yanked_reason": null
			},
			{
				"comment_text": "",
				"digests": {
					"md5": "2c0ae04171e1e8964ceeb809ba5f14b1",
					"sha256": "6d0ce4fa759cb99fe1e4d7ee171d2f90925867662f1355510f1448960efb10e3"
				},
				"downloads": -1,
				"filename": "awslogs-0.11.0.tar.gz",
				"has_sig": false,
				"md5_digest": "2c0ae04171e1e8964ceeb809ba5f14b1",
				"packagetype": "sdist",
				"python_version": "source",
				"requires_python": null,
				"size": 11912,
				"upload_time": "2018-12-02T13:36:09",
				"upload_time_iso_8601": "2018-12-02T13:36:09.166923Z",
				"url": "https://files.pythonhosted.org/packages/87/56/aa4b877b7248bd2ff0b5d8b1aafb6719f44149e90876c6e0bfe190ed98c9/awslogs-0.11.0.tar.gz",
				"yanked": false,
				"yanked_reason": null
			}
		],
		"0.13.0": [
			{
				"comment_text": "",
				"digests": {
					"md5": "30d7c2e05d822ce0115786bc01c292f2",
					"sha256": "9f2af8c4bd64011ccccd2e3e7b1c9bbf97319ea9ec3ce1bca55dbac156e79c50"
				},
				"downloads": -1,
				"filename": "awslogs-0.13.0-py2.py3-none-any.whl",
				"has_sig": false,
				"md5_digest": "30d7c2e05d822ce0115786bc01c292f2",
				"packagetype": "bdist_wheel",
				"python_version": "py2.py3",
				"requires_python": ">=3.5.*",
				"size": 13277,
				"upload_time": "2020-07-09T21:15:33",
				"upload_time_iso_8601": "2020-07-09T21:15:33.664540Z",
				"url": "https://files.pythonhosted.org/packages/b7/ad/550dcffbf0be3acfd6731d594c80ffa3a4420d6c31c666cdaabaed44641f/awslogs-0.13.0-py2.py3-none-any.whl",
				"yanked": false,
				"yanked_reason": null
			},
			{
				"comment_text": "",
				"digests": {
					"md5": "7f99210404e9a23e626e5f0bc203cb10",
					"sha256": "f46571ebc937b3bb3e15b18545f124054386d2b03cbc852e44233aebe3350ebf"
				},
				"downloads": -1,
				"filename": "awslogs-0.13.0.tar.gz",
				"has_sig": false,
				"md5_digest": "7f99210404e9a23e626e5f0bc203cb10",
				"packagetype": "sdist",
				"python_version": "source",
				"requires_python": ">=3.5.*",
				"size": 15428,
				"upload_time": "2020-07-09T21:15:34",
				"upload_time_iso_8601": "2020-07-09T21:15:34.873733Z",
				"url": "https://files.pythonhosted.org/packages/a7/2c/953fa299472f6bc59094b868249b6e63cd8fdf114bfb6d9d96068fbdeff2/awslogs-0.13.0.tar.gz",
				"yanked": false,
				"yanked_reason": null
			}
		],
		"0.14.0": [
			{
				"comment_text": "",
				"digests": {
					"md5": "234cf471d548d2088e77af787c68cc9f",
					"sha256": "a47d368329679876c90ba9a5391dcdcb6c7fe237768dd1487c54752f835e2e76"
				},
				"downloads": -1,
				"filename": "awslogs-0.14.0-py2.py3-none-any.whl",
				"has_sig": false,
				"md5_digest": "234cf471d548d2088e77af787c68cc9f",
				"packagetype": "bdist_wheel",
				"python_version": "py2.py3",
				"requires_python": ">=3.5.*",
				"size": 13388,
				"upload_time": "2020-07-10T07:14:51",
				"upload_time_iso_8601": "2020-07-10T07:14:51.094784Z",
				"url": "https://files.pythonhosted.org/packages/28/ad/4cd970ce342cb38d475c6e02c09a241ffb35f77c0539549bb08a0852262d/awslogs-0.14.0-py2.py3-none-any.whl",
				"yanked": false,
				"yanked_reason": null
			},
			{
				"comment_text": "",
				"digests": {
					"md5": "35e0bfb57bea68286935356136e5ed87",
					"sha256": "1b249f87fa2adfae39b9867f3066ac00b9baf401f4783583ab28fcdea338f77e"
				},
				"downloads": -1,
				"filename": "awslogs-0.14.0.tar.gz",
				"has_sig": false,
				"md5_digest": "35e0bfb57bea68286935356136e5ed87",
				"packagetype": "sdist",
				"python_version": "source",
				"requires_python": ">=3.5.*",
				"size": 15634,
				"upload_time": "2020-07-10T07:14:52",
				"upload_time_iso_8601": "2020-07-10T07:14:52.852816Z",
				"url": "https://files.pythonhosted.org/packages/96/7b/20bff9839d6679e25d989f94ca4320466ec94f3441972aadaafbad50560f/awslogs-0.14.0.tar.gz",
				"yanked": false,
				"yanked_reason": null
			}
		],
		"0.2.0": [
			{
				"comment_text": "",
				"digests": {
					"md5": "7229829c3382827516882d31cdaf8c7b",
					"sha256": "3f18a488f61b4db2b664a7622da0cd61e293aaa1f20dae52f692fc66d1d5dcd8"
				},
				"downloads": -1,
				"filename": "awslogs-0.2.0.tar.gz",
				"has_sig": false,
				"md5_digest": "7229829c3382827516882d31cdaf8c7b",
				"packagetype": "sdist",
				"python_version": "source",
				"requires_python": null,
				"size": 11361,
				"upload_time": "2016-01-14T21:33:01",
				"upload_time_iso_8601": "2016-01-14T21:33:01.738734Z",
				"url": "https://files.pythonhosted.org/packages/a1/43/38336793f46ae51e8b5931e935908e4c208b84d2dc689f34ff209603b74f/awslogs-0.2.0.tar.gz",
				"yanked": false,
				"yanked_reason": null
			}
		],
		"0.3.0": [
			{
				"comment_text": "",
				"digests": {
					"md5": "fa461b1f5715c2f4d1cc26407b1c62df",
					"sha256": "d15f51b66cf9c0cd37e1197ebb143f0fc0440ca2c24f7a41212f6577d7e2a2d3"
				},
				"downloads": -1,
				"filename": "awslogs-0.3.0.tar.gz",
				"has_sig": false,
				"md5_digest": "fa461b1f5715c2f4d1cc26407b1c62df",
				"packagetype": "sdist",
				"python_version": "source",
				"requires_python": null,
				"size": 12235,
				"upload_time": "2016-02-05T16:42:38",
				"upload_time_iso_8601": "2016-02-05T16:42:38.905021Z",
				"url": "https://files.pythonhosted.org/packages/98/59/43424285d5e2319036e59bee8e1e979ed58dbc73e4e22914beed8b5d0f4b/awslogs-0.3.0.tar.gz",
				"yanked": false,
				"yanked_reason": null
			}
		],
		"0.4.0": [
			{
				"comment_text": "",
				"digests": {
					"md5": "613c35dc6561a8ebfcd8a4c8c6bac798",
					"sha256": "e0f5ac669f24d719119f757d158080f9e1672ffffff5b11f3dbabdbee0fd9356"
				},
				"downloads": -1,
				"filename": "awslogs-0.4.0.tar.gz",
				"has_sig": false,
				"md5_digest": "613c35dc6561a8ebfcd8a4c8c6bac798",
				"packagetype": "sdist",
				"python_version": "source",
				"requires_python": null,
				"size": 12414,
				"upload_time": "2016-02-28T22:14:01",
				"upload_time_iso_8601": "2016-02-28T22:14:01.810891Z",
				"url": "https://files.pythonhosted.org/packages/51/bf/591ea0b4c7f1033bebe69fb740988bf93ed7123043be64119cfb5c47c129/awslogs-0.4.0.tar.gz",
				"yanked": false,
				"yanked_reason": null
			}
		],
		"0.5.0": [
			{
				"comment_text": "",
				"digests": {
					"md5": "4153f961e06bdcfeddaa2a90acdb5af6",
					"sha256": "317cd33532e98986f88106fe70abbfe665c6f4b8a4f215377d4c3dc266712d6c"
				},
				"downloads": -1,
				"filename": "awslogs-0.5.0.tar.gz",
				"has_sig": false,
				"md5_digest": "4153f961e06bdcfeddaa2a90acdb5af6",
				"packagetype": "sdist",
				"python_version": "source",
				"requires_python": null,
				"size": 10369,
				"upload_time": "2016-05-11T21:09:54",
				"upload_time_iso_8601": "2016-05-11T21:09:54.939089Z",
				"url": "https://files.pythonhosted.org/packages/bb/f5/dc8d0525c2588fd75a10cfd05d983f21af7bdde30f0573da3a9bf273d375/awslogs-0.5.0.tar.gz",
				"yanked": false,
				"yanked_reason": null
			}
		],
		"0.6.0": [
			{
				"comment_text": "",
				"digests": {
					"md5": "7e3812cd5c239926c4c1ff1fd7fbd0f3",
					"sha256": "68e7ee5c7628fc95b6a3dc472d53a54f5ab12e02f0e7d64233ba3b4ee6fb7d7a"
				},
				"downloads": -1,
				"filename": "awslogs-0.6.0-py2.py3-none-any.whl",
				"has_sig": false,
				"md5_digest": "7e3812cd5c239926c4c1ff1fd7fbd0f3",
				"packagetype": "bdist_wheel",
				"python_version": "2.7",
				"requires_python": null,
				"size": 8862,
				"upload_time": "2016-08-21T09:09:02",
				"upload_time_iso_8601": "2016-08-21T09:09:02.016135Z",
				"url": "https://files.pythonhosted.org/packages/b1/fd/e00ee1e3edbb8d03374cd30260712842437feed55d87a6e53583af0d12e4/awslogs-0.6.0-py2.py3-none-any.whl",
				"yanked": false,
				"yanked_reason": null
			},
			{
				"comment_text": "",
				"digests": {
					"md5": "80f09787f9592fa0e2f0ca3e51db23e0",
					"sha256": "46949cfeb07c47f4ee9a55844205d281faa896d315b9a0164741372f65658b70"
				},
				"downloads": -1,
				"filename": "awslogs-0.6.0.tar.gz",
				"has_sig": false,
				"md5_digest": "80f09787f9592fa0e2f0ca3e51db23e0",
				"packagetype": "sdist",
				"python_version": "source",
				"requires_python": null,
				"size": 10527,
				"upload_time": "2016-08-21T09:08:59",
				"upload_time_iso_8601": "2016-08-21T09:08:59.363993Z",
				"url": "https://files.pythonhosted.org/packages/94/35/87d0aba34bf5ff219e6d446e3f37a44c031be9515f6c7e5bd45585f16eac/awslogs-0.6.0.tar.gz",
				"yanked": false,
				"yanked_reason": null
			}
		],
		"0.7.0": [
			{
				"comment_text": "",
				"digests": {
					"md5": "8a98cbd0439198e11715a208d313712d",
					"sha256": "cf72ca441c335f91fd93570dedc1faa3e4966bb8cea9f874a1e017a58de4dcfe"
				},
				"downloads": -1,
				"filename": "awslogs-0.7.0-py2.py3-none-any.whl",
				"has_sig": false,
				"md5_digest": "8a98cbd0439198e11715a208d313712d",
				"packagetype": "bdist_wheel",
				"python_version": "2.7",
				"requires_python": null,
				"size": 9153,
				"upload_time": "2017-04-26T13:23:53",
				"upload_time_iso_8601": "2017-04-26T13:23:53.290935Z",
				"url": "https://files.pythonhosted.org/packages/01/38/fe3b67dad047b39bfa4759ee5dcf1adce051134b2fa3287a2397e5b6d610/awslogs-0.7.0-py2.py3-none-any.whl",
				"yanked": false,
				"yanked_reason": null
			},
			{
				"comment_text": "",
				"digests": {
					"md5": "f4d789f55d327c79623f8232540fd1ef",
					"sha256": "b9a2b1247579e0283bd12cd2f42c971a9b8ffe87ab8bda318c7604a086556a4e"
				},
				"downloads": -1,
				"filename": "awslogs-0.7.0.tar.gz",
				"has_sig": false,
				"md5_digest": "f4d789f55d327c79623f8232540fd1ef",
				"packagetype": "sdist",
				"python_version": "source",
				"requires_python": null,
				"size": 11096,
				"upload_time": "2016-09-10T08:37:41",
				"upload_time_iso_8601": "2016-09-10T08:37:41.263498Z",
				"url": "https://files.pythonhosted.org/packages/5e/ca/7f0240ee5651f2689928ce10665dd1f0d8078c6a84fcea02f5c8ff1b4b15/awslogs-0.7.0.tar.gz",
				"yanked": false,
				"yanked_reason": null
			}
		],
		"0.8.0": [
			{
				"comment_text": "",
				"digests": {
					"md5": "8bae58b87aa12ab188fe9760affc9c92",
					"sha256": "9bd961b7b7eb3137aedd5806700d9830916bb59f2bf20bb8e5a1f235b69fdcbf"
				},
				"downloads": -1,
				"filename": "awslogs-0.8.0-py2.py3-none-any.whl",
				"has_sig": false,
				"md5_digest": "8bae58b87aa12ab188fe9760affc9c92",
				"packagetype": "bdist_wheel",
				"python_version": "2.7",
				"requires_python": null,
				"size": 9246,
				"upload_time": "2017-04-26T13:24:30",
				"upload_time_iso_8601": "2017-04-26T13:24:30.417292Z",
				"url": "https://files.pythonhosted.org/packages/4c/02/ce6f0d612c27074f96156cf962ff019ba618cd6210280d2c60097c25cb57/awslogs-0.8.0-py2.py3-none-any.whl",
				"yanked": false,
				"yanked_reason": null
			},
			{
				"comment_text": "",
				"digests": {
					"md5": "31d055c1e0301bd6b1b7312a55587276",
					"sha256": "da2551a3b3e9bb0beeaaf779cfe6139e21f764d08602b7b863196c600477f761"
				},
				"downloads": -1,
				"filename": "awslogs-0.8.0.tar.gz",
				"has_sig": false,
				"md5_digest": "31d055c1e0301bd6b1b7312a55587276",
				"packagetype": "sdist",
				"python_version": "source",
				"requires_python": null,
				"size": 11243,
				"upload_time": "2017-01-13T11:30:45",
				"upload_time_iso_8601": "2017-01-13T11:30:45.089493Z",
				"url": "https://files.pythonhosted.org/packages/59/7a/43ef6954fcba7ddd75e800277792297d98119ffcdf462101fde2b63a0b37/awslogs-0.8.0.tar.gz",
				"yanked": false,
				"yanked_reason": null
			}
		]
	},
	"urls": [
		{
			"comment_text": "",
			"digests": {
				"md5": "234cf471d548d2088e77af787c68cc9f",
				"sha256": "a47d368329679876c90ba9a5391dcdcb6c7fe237768dd1487c54752f835e2e76"
			},
			"downloads": -1,
			"filename": "awslogs-0.14.0-py2.py3-none-any.whl",
			"has_sig": false,
			"md5_digest": "234cf471d548d2088e77af787c68cc9f",
			"packagetype": "bdist_wheel",
			"python_version": "py2.py3",
			"requires_python": ">=3.5.*",
			"size": 13388,
			"upload_time": "2020-07-10T07:14:51",
			"upload_time_iso_8601": "2020-07-10T07:14:51.094784Z",
			"url": "https://files.pythonhosted.org/packages/28/ad/4cd970ce342cb38d475c6e02c09a241ffb35f77c0539549bb08a0852262d/awslogs-0.14.0-py2.py3-none-any.whl",
			"yanked": false,
			"yanked_reason": null
		},
		{
			"comment_text": "",
			"digests": {
				"md5": "35e0bfb57bea68286935356136e5ed87",
				"sha256": "1b249f87fa2adfae39b9867f3066ac00b9baf401f4783583ab28fcdea338f77e"
			},
			"downloads": -1,
			"filename": "awslogs-0.14.0.tar.gz",
			"has_sig": false,
			"md5_digest": "35e0bfb57bea68286935356136e5ed87",
			"packagetype": "sdist",
			"python_version": "source",
			"requires_python": ">=3.5.*",
			"size": 15634,
			"upload_time": "2020-07-10T07:14:52",
			"upload_time_iso_8601": "2020-07-10T07:14:52.852816Z",
			"url": "https://files.pythonhosted.org/packages/96/7b/20bff9839d6679e25d989f94ca4320466ec94f3441972aadaafbad50560f/awslogs-0.14.0.tar.gz",
			"yanked": false,
			"yanked_reason": null
		}
	],
	"vulnerabilities": []
}

ライセンスを調べるツールを導入する方法

以下のツールをインストールすることでライセンス情報を調べることが可能
https://pypi.org/project/pip-licenses/

$pip install -U pip-licenses 
$pip-licenses

以下のコードでローカルのパッケージの情報を抽出している模様。
https://github.com/raimon49/pip-licenses/blob/master/piplicenses.py#L48

自力でパッケージ情報をCSVに出力するコード例

ローカルのパッケージあるいはPipfile.lockに記載されたパッケージの情報をCSVに出力するコード例


import subprocess
import requests
import sys
import csv
import argparse
import json


def find_classifiers(classifiers, key):
    for item in classifiers:
        if key in item:
            return item
    return None


def get_pypi(module_name, version):
    res = requests.get(f'https://pypi.org/pypi/{module_name}/{version}/json')
    if res.status_code != 200:
        print(
            f'not found {module_name}/{version} in pypi.org',
            file=sys.stderr
        )
        return {
            'home_page': '',
            'license': ''
        }
    data = res.json()
    classifiers = data['info']['classifiers']
    home_page = data['info']['home_page']
    if not home_page:
        home_page = data['info']['project_url']
    license = data['info']['license']
    if not license:
        license = find_classifiers(classifiers, 'License')
    return {
        'home_page': home_page,
        'license': license
    }


def analyze_local(pipcmd):
    process = subprocess.run([pipcmd, 'list', '--format=json'], capture_output=True)
    output = process.stdout.decode('utf-8')
    lines = json.loads(output)
    for item in lines:
        yield {
            'module_name': item['name'],
            'version': item['version']
        }


def analyze_pipfile_lock(pipfile_lock_path):
    with open(pipfile_lock_path, 'r', encoding='utf-8') as fr:
        lock_data = json.load(fr)
        for key in lock_data.keys():
            if key == '_meta':
                continue
            for module_name in lock_data[key].keys():
                version = lock_data[key][module_name]['version'][2:]
                yield {
                    'module_name': module_name,
                    'version': version
                }


parser = argparse.ArgumentParser(description="pythonのライブラリ情報をCSVに出力する")
parser.add_argument("output_path", type=str, help="出力CSVパス")
parser.add_argument(
    "--pip_cmd", type=str, default="pip", help="pipコマンド名"
)
parser.add_argument(
    "--pipfile_lock_path", type=str, default="", help="解析対象のPipfile.lockのパス"
)
args = parser.parse_args()

with open(args.output_path, "w", encoding="utf-8", errors="ignore") as fw:
    writer = csv.writer(fw, quoting=csv.QUOTE_ALL)
    if args.pipfile_lock_path:
        items = analyze_pipfile_lock(args.pipfile_lock_path)
    else:
        items = analyze_local(args.pip_cmd)
    for item in items:
        module_name = item['module_name']
        version = item['version']
        data = get_pypi(module_name, version)
        writer.writerow([
            module_name,
            version,
            data['home_page'],
            data['license']
        ])


実行方法

ローカルのパッケージ情報をoutput.csvに出力する

python3 check_local.py output.csv

指定のPipfile.lock中のパッケージ情報をoutput2.csvに出力する

python3 check_local.py output2.csv --pipfile_lock_path="hogehoge/Pipfile.lock"

Discussion