Python library to generate and execute code dynamically
Project description
codeg
Codeg (code generator) is a python library that allows you to generate python code dynamically.
This library is still a work in progress
Quickstart
Let's say you want to generate the following class dynamically
class Animal:
def __init__(name: str):
self.name = name
You can use the following code
import codeg
code_cls = codeg.cls("Animal")
code__init = code_cls.method(
"__init__", attributes=[codeg.Attribute("name", annotation=str)]
)
code__init.line("self.name = name")
code_cls.print() # print the generated code
Animal = code_cls.build() # eval the code and get it on a variable
animal = Animal("rex")
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
codeg-0.2.0.tar.gz
(9.5 kB
view details)
Built Distribution
codeg-0.2.0-py3-none-any.whl
(15.8 kB
view details)
File details
Details for the file codeg-0.2.0.tar.gz
.
File metadata
- Download URL: codeg-0.2.0.tar.gz
- Upload date:
- Size: 9.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.4.2 requests/2.27.1 setuptools/45.2.0 requests-toolbelt/0.8.0 tqdm/4.30.0 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 61baacb3669f45bc2ddcdb87353dbb07b64a5f2dcd13d3eadabc290b369f43b3 |
|
MD5 | 6fe4fe4c1b77a89f36d9993180b15c22 |
|
BLAKE2b-256 | 0083fccd7b8dbd5e07605092013238a810e62901b4cf36084274c048bfbc7a9f |
File details
Details for the file codeg-0.2.0-py3-none-any.whl
.
File metadata
- Download URL: codeg-0.2.0-py3-none-any.whl
- Upload date:
- Size: 15.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.4.2 requests/2.27.1 setuptools/45.2.0 requests-toolbelt/0.8.0 tqdm/4.30.0 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | bf751c6729d0dbe0c92f50e17efe77c115063455367723af5d5aeb630c89c3d8 |
|
MD5 | 10e25172fcb3431ef9c67facfac3d449 |
|
BLAKE2b-256 | 23b3d70e1549bf5fcc387f3a8b6265ced0e3c1522245284172b693f1b4753d19 |