A way to get the source code of functions
Project description
This library is needed to obtain the source code of functions at runtime. It can be used, for example, as a basis for libraries that work with AST on the fly. In fact, it is a thin layer built around inspect.getsource and dill.source.getsource.
Installation
You can install getsources using pip:
pip install getsources
You can also quickly try out this and other packages without having to install using instld.
Usage
The basic function of the library is getsource, which works similarly to the function of the same name from the standard library:
from getsources import getsource
def function():
...
print(getsource(function))
#> def function():
#> ...
Unlike its counterpart from the standard library, this thing can also work:
- With lambda functions
- With functions defined inside REPL
We also often need to trim excess indentation from a function object to make it easier to further process the resulting code. To do this, use the getclearsource function:
from getsources import getclearsource
class SomeClass:
@staticmethod
def method():
...
print(getclearsource(SomeClass.method))
#> @staticmethod
#> def method():
#> ...
As you can see, the resulting source code text has no extra indentation, but in all other respects this function is completely identical to the usual getsource.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file getsources-0.0.2.tar.gz.
File metadata
- Download URL: getsources-0.0.2.tar.gz
- Upload date:
- Size: 5.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ed83fb44b654f8a257f552be400430502353a52b03e88cd4568996405862d921
|
|
| MD5 |
0c3f5eb31ae4c87feb15678a71510307
|
|
| BLAKE2b-256 |
04a8ec2a280de2f2de1fc7dd7b4d6356be2576895141cf9790bccc146d55a2f0
|
Provenance
The following attestation bundles were made for getsources-0.0.2.tar.gz:
Publisher:
release.yml on mutating/getsources
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
getsources-0.0.2.tar.gz -
Subject digest:
ed83fb44b654f8a257f552be400430502353a52b03e88cd4568996405862d921 - Sigstore transparency entry: 992172498
- Sigstore integration time:
-
Permalink:
mutating/getsources@f261e9885a7ddb66173bcdf98726436b907aa130 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/mutating
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@f261e9885a7ddb66173bcdf98726436b907aa130 -
Trigger Event:
push
-
Statement type:
File details
Details for the file getsources-0.0.2-py3-none-any.whl.
File metadata
- Download URL: getsources-0.0.2-py3-none-any.whl
- Upload date:
- Size: 4.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0639f7c7237830be40bf0e1fad48b7a365db1d741552e23d4b9b62f83110cb62
|
|
| MD5 |
da3450d92a9cf5771689e9cbcdb4ea8f
|
|
| BLAKE2b-256 |
6167531d79f148369c52b14936e62c1f80830e764c18285666951d4395a451f3
|
Provenance
The following attestation bundles were made for getsources-0.0.2-py3-none-any.whl:
Publisher:
release.yml on mutating/getsources
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
getsources-0.0.2-py3-none-any.whl -
Subject digest:
0639f7c7237830be40bf0e1fad48b7a365db1d741552e23d4b9b62f83110cb62 - Sigstore transparency entry: 992172499
- Sigstore integration time:
-
Permalink:
mutating/getsources@f261e9885a7ddb66173bcdf98726436b907aa130 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/mutating
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@f261e9885a7ddb66173bcdf98726436b907aa130 -
Trigger Event:
push
-
Statement type: