Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/MatteoH2O1999/python_code_extractor
Python package to extract source code from live object
https://github.com/MatteoH2O1999/python_code_extractor
Last synced: 3 months ago
JSON representation
Python package to extract source code from live object
- Host: GitHub
- URL: https://github.com/MatteoH2O1999/python_code_extractor
- Owner: MatteoH2O1999
- License: agpl-3.0
- Created: 2022-08-08T12:45:36.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2023-12-14T03:35:33.000Z (11 months ago)
- Last Synced: 2024-04-18T06:59:54.795Z (7 months ago)
- Language: Python
- Size: 85.9 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Python code extractor
Python code extractor
## Dependencies
Written in pure `Python` and has no dependencies other than the base libraries.
## Installation
From source code:
```commandline
pip install .
```From `PyPI`:
```commandline
pip install code-extractor
```## Import
### Main functions
```python
import code_extractor
from code_extractor import extract_code, load_code
```### Pickle API
```python
import code_extractor.pickle
```or as a drop-in for `pickle`:
```python
import code_extractor.pickle as pickle
```## Usage
Given the following:
```python
class Class:
def __init__(self):
self.test = 42def function():
return 42
```Use
```pycon
>>> import code_extractor
>>> extracted_class = code_extractor.extract_code(Class)
>>> extracted_function = code_extractor.extract_code(function)
>>> reconstructed_class = code_extractor.load_code(extracted_class)
>>> instance = reconstructed_class()
>>> instance.test
42
>>> reconstructed_function = code_extractor.load_code(extracted_function)
>>> reconstructed_function()
42
```## Pickle module
```pycon
>>> import code_extractor
>>> code_extractor.dump(...)
>>> code_extractor.dumps(...)
>>> code_extractor.load(...)
>>> code_extractor.loads(...)
```Or
```pycon
>>> import code_extractor.pickle as pickle
>>> pickle.dump(...)
>>> pickle.dumps(...)
>>> pickle.load(...)
>>> pickle.loads(...)
```