resid
Description
Resid is a python library for analysing resource identifiers for extracting valuable information. This can include guessing content type, encoding, wheather contents are available locally or if it resembles file path, url, etc.
In this library, source is defined as similar to uri but source can be anything including file object. 'source' is defined as anything that can be used to access/locate contents. That can include url, file path, file object and others depending on wheather they can be used to access data or get information about it.
Any object can be used as source but not all of them will be supported. This library helps in extracting information about source such as wheather source is supported or guessing its content type.
Only urls, file-paths, dir-paths, file-like-objects, path-like-objects are currenly supported.
Install
Enter this on your command-line application:
pip install resid
Usage
Importing resid
import resid
resid -> Resource Identifier
Check support of source
View supported source as a valid file path and resembled as file path that may not be valid but looks like file path.
>>> resid.is_supported("https://stackoverflow.com/")
True
>>> resid.is_supported("not_exists.txt")
False
>>> resid.is_resembled("not_exists.txt")
True
>>> resid.is_supported(io.BytesIO())
True
>>> resid.is_resembled(object)
False
Most functions will return
Noneif source is not supported.
Check if source falls in category
>>> resid.is_url("https://example.com/")
True
>>> resid.is_web_url("https://example.com/")
True
>>> resid.is_file_path("https://example.com/")
False
>>> resid.is_file_path("sample.txt")
True
>>> resid.is_file_path(object)
False
>>> resid.is_file_like(io.BytesIO())
True
>>> resid.is_path_like(pathlib.Path("sample.txt"))
True
Guess content type
>>> resid.guess_content_type("sample.txt")
'text/plain'
>>> resid.guess_content_type("https://example.com/")
'text/html'
>>> resid.guess_content_type("https://example.com/files/sample.pdf")
'application/pdf'
>>> resid.guess_content_type(open("sample.txt"))
'text/plain'
Check if contents are hosted locally or remotely
>>> resid.locally_hosted("sample.txt")
True
>>> resid.locally_hosted("https://example.com/")
False
>>> resid.locally_hosted("http://127.0.0.1/")
True
>>> resid.guess_content_type(open("sample.txt"))
True
>>> resid.remotely_hosted("sample.txt")
False
>>> resid.remotely_hosted("https://example.com/")
True
>>> resid.remotely_hosted("file:///home/sample.txt")
False
Guess type of source
>>> resid.guess_type("sample.txt")
'file-path'
>>> resid.guess_type("contents/")
'dir-path'
>>> resid.guess_type("https://example.com/")
'web-url'
>>> resid.guess_type(io.BytesIO())
'file-like-object'
>>> resid.guess_type(pathlib.Path("sample.txt"))
'file-path-like-object'
>>> resid.guess_type("file:///home/sample.txt")
'local-file-url'
Convert source to string
>>> resid.to_string(open("setup.py"))
'setup.py'
>>> resid.to_string(pathlib.Path("sample.txt"))
'sample.txt'
>>> resid.to_string("https://example.com/")
'https://example.com/'
Alternate Usage
File path example
>>> file_res = resid.find_resource("setup.py")
>>> file_res.supported
True
>>> file_res.content_type
'text/plain'
>>> file_res.path
'setup.py'
>>> file_res.size
41
>>> file_res.mod_time
1661489762.1989822
Directory example
>>> dir_res = resid.find_resource("https://example.com/")
>>> list(dir_res.files)
['.venv\\pyvenv.cfg']
>>> list(dir_res.dirs)
['.venv\\Include', '.venv\\Lib', '.venv\\Scripts']
>>> list(dir_res.files_recursive)
...
>>> list(dir_res.dirs_recursive)
...
URL example
>>> url_res = resid.find_resource("https://example.com/")
>>> url_res.content_type
'text/html'
>>> url_res.scheme
'https'
>>> url_res.hostname
'example.com'
>>> list(dir_res.files)
['.venv\\pyvenv.cfg']
>>> list(dir_res.dirs)
['.venv\\Include', '.venv\\Lib', '.venv\\Scripts']
>>> list(dir_res.files_recursive)
...
>>> list(dir_res.dirs_recursive)
...
About
Resid was developed based on navaly library to be used with navaly. It relect a portion of navaly which is split to its own project for reuse. Resid can still be used with other python projects as seen in the examples above.
Metadata
Release files for resid 0.0.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| resid-0.0.3.tar.gz | 14.8 kB | Without provenance | Details for resid-0.0.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| resid-0.0.3-py3-none-any.whl | Python 3 | none | any | Details for resid-0.0.3-py3-none-any.whl |
Total release size: 31.2 kB
Release files / resid-0.0.3.tar.gz
| Download URL | resid-0.0.3.tar.gz |
|---|---|
| Size | 14.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5fdcfd8241e21ddea1fc5f4360feccd795f5ba1226b146d06a7f427661ea15ec
|
|
BLAKE2b-256 checksum How to use checksums |
4f9b7dc5454ea5531de369b2b13aa6051bab951b06669d210e065b22a55d2a91
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.10.0
|
Release files / resid-0.0.3-py3-none-any.whl
| Download URL | resid-0.0.3-py3-none-any.whl |
|---|---|
| Size | 16.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
6be00c7156b1e3e05ffe36a0c0baac35e4f38d0ef461bb16cd0ce77f088bd9c0
|
|
BLAKE2b-256 checksum How to use checksums |
c2826b28236eaabb50cf948db850ed074eabe4d60008747ff743a8a0d5af1c7a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.10.0
|
Security for resid 0.0.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.