{"id":13502300,"url":"https://github.com/ahupp/python-magic","last_synced_at":"2026-02-21T06:31:24.069Z","repository":{"id":856458,"uuid":"589189","full_name":"ahupp/python-magic","owner":"ahupp","description":"A python wrapper for libmagic","archived":false,"fork":false,"pushed_at":"2025-10-13T21:11:24.000Z","size":1207,"stargazers_count":2839,"open_issues_count":26,"forks_count":303,"subscribers_count":44,"default_branch":"master","last_synced_at":"2025-11-10T04:31:39.117Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ahupp.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG","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,"zenodo":null}},"created_at":"2010-03-31T22:40:33.000Z","updated_at":"2025-11-08T14:50:46.000Z","dependencies_parsed_at":"2023-02-13T00:16:15.911Z","dependency_job_id":"eb48dd3a-b526-41a4-a1e0-8d46901ce0f5","html_url":"https://github.com/ahupp/python-magic","commit_stats":{"total_commits":279,"total_committers":64,"mean_commits":4.359375,"dds":0.3870967741935484,"last_synced_commit":"067399b1ae104975fe83b5162dd3b83788cdfdd0"},"previous_names":[],"tags_count":20,"template":false,"template_full_name":null,"purl":"pkg:github/ahupp/python-magic","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ahupp%2Fpython-magic","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ahupp%2Fpython-magic/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ahupp%2Fpython-magic/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ahupp%2Fpython-magic/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ahupp","download_url":"https://codeload.github.com/ahupp/python-magic/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ahupp%2Fpython-magic/sbom","scorecard":{"id":78993,"data":{"date":"2025-08-11","repo":{"name":"github.com/ahupp/python-magic","commit":"8361a3333b73cd5c06fa6dc067b6d31c5b4245df"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":3.9,"checks":[{"name":"Code-Review","score":4,"reason":"Found 11/24 approved changesets -- score normalized to 4","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Maintained","score":1,"reason":"2 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 1","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Dangerous-Workflow","score":10,"reason":"no dangerous workflow patterns detected","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Pinned-Dependencies","score":0,"reason":"dependency not pinned by hash detected -- score normalized to 0","details":["Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yml:17: update your workflow using https://app.stepsecurity.io/secureworkflow/ahupp/python-magic/ci.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yml:18: update your workflow using https://app.stepsecurity.io/secureworkflow/ahupp/python-magic/ci.yml/master?enable=pin","Warn: pipCommand not pinned by hash: .github/workflows/ci.yml:23","Warn: pipCommand not pinned by hash: .github/workflows/ci.yml:24","Warn: pipCommand not pinned by hash: .github/workflows/ci.yml:25","Info:   0 out of   2 GitHub-owned GitHubAction dependencies pinned","Info:   0 out of   3 pipCommand dependencies pinned"],"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"Token-Permissions","score":0,"reason":"detected GitHub workflow tokens with excessive permissions","details":["Warn: no topLevel permission defined: .github/workflows/ci.yml:1","Info: no jobLevel write permissions found"],"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}},{"name":"License","score":9,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Warn: project license file does not contain an FSF or OSI license."],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 21 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}}]},"last_synced_at":"2025-08-15T05:23:55.526Z","repository_id":856458,"created_at":"2025-08-15T05:23:55.527Z","updated_at":"2025-08-15T05:23:55.527Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29675440,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-21T06:23:40.028Z","status":"ssl_error","status_checked_at":"2026-02-21T06:23:39.222Z","response_time":107,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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-07-31T22:02:09.210Z","updated_at":"2026-02-21T06:31:24.051Z","avatar_url":"https://github.com/ahupp.png","language":"Python","readme":"# python-magic\n[![PyPI version](https://badge.fury.io/py/python-magic.svg)](https://badge.fury.io/py/python-magic)\n[![ci](https://github.com/ahupp/python-magic/actions/workflows/ci.yml/badge.svg)](https://github.com/ahupp/python-magic/actions/workflows/ci.yml)\n[![Join the chat at https://gitter.im/ahupp/python-magic](https://badges.gitter.im/ahupp/python-magic.svg)](https://gitter.im/ahupp/python-magic?utm_source=badge\u0026utm_medium=badge\u0026utm_campaign=pr-badge\u0026utm_content=badge)\n\npython-magic is a Python interface to the libmagic file type\nidentification library.  libmagic identifies file types by checking\ntheir headers according to a predefined list of file types. This\nfunctionality is exposed to the command line by the Unix command\n`file`.\n\n## Usage\n\n```python\n\u003e\u003e\u003e import magic\n\u003e\u003e\u003e magic.from_file(\"testdata/test.pdf\")\n'PDF document, version 1.2'\n# recommend using at least the first 2048 bytes, as less can produce incorrect identification\n\u003e\u003e\u003e magic.from_buffer(open(\"testdata/test.pdf\", \"rb\").read(2048))\n'PDF document, version 1.2'\n\u003e\u003e\u003e magic.from_file(\"testdata/test.pdf\", mime=True)\n'application/pdf'\n```\n\nThere is also a `Magic` class that provides more direct control,\nincluding overriding the magic database file and turning on character\nencoding detection.  This is not recommended for general use.  In\nparticular, it's not safe for sharing across multiple threads and\nwill fail throw if this is attempted.\n\n```python\n\u003e\u003e\u003e f = magic.Magic(uncompress=True)\n\u003e\u003e\u003e f.from_file('testdata/test.gz')\n'ASCII text (gzip compressed data, was \"test\", last modified: Sat Jun 28\n21:32:52 2008, from Unix)'\n```\n\nYou can also combine the flag options:\n\n```python\n\u003e\u003e\u003e f = magic.Magic(mime=True, uncompress=True)\n\u003e\u003e\u003e f.from_file('testdata/test.gz')\n'text/plain'\n```\n\n## Installation\n\nThe current stable version of python-magic is available on PyPI and\ncan be installed by running:\n```\npip install python-magic\n```\n\nOther sources:\n\n- PyPI: http://pypi.python.org/pypi/python-magic/\n- GitHub: https://github.com/ahupp/python-magic\n\nThis module is a simple wrapper around the libmagic C library, and\nthat must be installed as well:\n\n### Debian/Ubuntu\n\n```\nsudo apt-get install libmagic1\n```\n\n### OSX\n\n- When using Homebrew: `brew install libmagic`\n- When using macports: `port install file`\n\nIf python-magic fails to load the library it may be in a non-standard location, in which case you can set the environment variable `DYLD_LIBRARY_PATH` to point to it.\n\n### SmartOS:\n- Install libmagic for source: https://github.com/file/file\n- Depending on your ./configure --prefix settings set your LD_LIBRARY_PATH to \u003cprefix\u003e/lib\n\n### Troubleshooting\n\n- 'MagicException: could not find any magic files!': some\n  installations of libmagic do not correctly point to their magic\n  database file.  Try specifying the path to the file explicitly in the\n  constructor: `magic.Magic(magic_file=\"path_to_magic_file\")`.\n\n- 'WindowsError: [Error 193] %1 is not a valid Win32 application':\n  Attempting to run the 32-bit libmagic DLL in a 64-bit build of\n  python will fail with this error.  Here are 64-bit builds of libmagic for windows: https://github.com/pidydx/libmagicwin64.\n  Newer version can be found here: https://github.com/nscaife/file-windows.\n\n- 'WindowsError: exception: access violation writing 0x00000000 ' This may indicate you are mixing\n  Windows Python and Cygwin Python. Make sure your libmagic and python builds are consistent.\n\n\n## Bug Reports\n\npython-magic is a thin layer over the libmagic C library.\nHistorically, most bugs that have been reported against python-magic\nare actually bugs in libmagic; libmagic bugs can be reported on their\ntracker here: https://bugs.astron.com/my_view_page.php.  If you're not\nsure where the bug lies feel free to file an issue on GitHub and I can\ntriage it.\n\n## Running the tests\n\nWe use the `tox` test runner which can be installed with `python -m pip install tox`.\n\nTo run tests locally across all available python versions:\n\n```\npython -m tox\n```\n\nOr to run just against a single version:\n\n```\npython -m tox py\n```\nTo run the tests across a variety of linux distributions (depends on Docker):\n\n```\n./test/run_all_docker_test.sh\n```\n\n## libmagic python API compatibility\n\nThe python bindings shipped with libmagic use a module name that conflicts with this package.  To work around this, python-magic includes a compatibility layer for the libmagic API.  See [COMPAT.md](COMPAT.md) for a guide to libmagic / python-magic compatibility.\n\n## Versioning\n\nMinor version bumps should be backwards compatible.  Major bumps are not.\n\n## Author\n\nWritten by Adam Hupp in 2001 for a project that never got off the\nground.  It originally used SWIG for the C library bindings, but\nswitched to ctypes once that was part of the python standard library.\n\nYou can contact me via my [website](http://hupp.org/adam) or\n[GitHub](http://github.com/ahupp).\n\n## License\n\npython-magic is distributed under the MIT license.  See the included\nLICENSE file for details.\n\nI am providing code in the repository to you under an open source license. Because this is my personal repository, the license you receive to my code is from me and not my employer (Facebook).\n","funding_links":[],"categories":["Files","资源列表","Python","Data Loading \u0026 Extraction","文件","文件操作","数据读写与提取","Files [🔝](#readme)","File Manipulation","Awesome Python"],"sub_categories":["文件","Files","HTTP Clients"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fahupp%2Fpython-magic","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fahupp%2Fpython-magic","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fahupp%2Fpython-magic/lists"}