Extract source code from python objects
Project description
Python code extractor
Python code extractor
Dependencies
Written in pure Python
and has no dependencies other than the base libraries.
Installation
From source code:
pip install .
From PyPI
:
pip install code-extractor
Import
Main functions
import code_extractor
from code_extractor import extract_code, load_code
Pickle API
import code_extractor.pickle
or as a drop-in for pickle
:
import code_extractor.pickle as pickle
Usage
Given the following:
class Class:
def __init__(self):
self.test = 42
def function():
return 42
Use
>>> 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
>>> import code_extractor
>>> code_extractor.dump(...)
>>> code_extractor.dumps(...)
>>> code_extractor.load(...)
>>> code_extractor.loads(...)
Or
>>> import code_extractor.pickle as pickle
>>> pickle.dump(...)
>>> pickle.dumps(...)
>>> pickle.load(...)
>>> pickle.loads(...)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
code-extractor-0.4.1.tar.gz
(21.9 kB
view details)
Built Distribution
File details
Details for the file code-extractor-0.4.1.tar.gz
.
File metadata
- Download URL: code-extractor-0.4.1.tar.gz
- Upload date:
- Size: 21.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.11.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7da792556b9b7c81b67bd4f97fd565a57e5f899467ec5074cc6428d6a62e062d |
|
MD5 | 768150d613e65740d78b51d5be67f10e |
|
BLAKE2b-256 | a5afefee2038b5381f55ea48091b71453d9b081872ddebd9755cc58aac95e5c2 |
File details
Details for the file code_extractor-0.4.1-py3-none-any.whl
.
File metadata
- Download URL: code_extractor-0.4.1-py3-none-any.whl
- Upload date:
- Size: 27.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.11.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9aac834b86a04fc0625ae0cdb2f499844bbdfbddff53372f11a0d17fea338f3f |
|
MD5 | f5ae21f4be78ac71ce0274cfb80d4236 |
|
BLAKE2b-256 | 24bbc309f0e5c38bc31a94ba73a8237ef622343fa857d9c58da4bdd6da81f352 |