configure your python class
Project description
ConPYguration
Configure your Python function or class with ConPYguration. ConPYguration is a Python library that allows you to easily configure your Python functions or classes with a configuration file or Dictionary.
Installation
pip install conpyguration
Usage
Basic Function
from conpyguration import get_conpyguration
def my_function(a, b=1) -> int:
return a + b
get_conpyguration(my_function)
# {
# 'description': <class 'conpyguration.types.UNDEFINED'>,
# 'module_name': '__main__',
# 'function_name': 'my_function',
# 'arguments': {
# 'a': {
# 'value_type': <class 'conpyguration.types.UNDEFINED'>,
# 'default': <class 'conpyguration.types.UNDEFINED'>,
# 'description': <class 'conpyguration.types.UNDEFINED'>,
# 'choices': <class 'conpyguration.types.UNDEFINED'>},
# 'b': {
# 'value_type': <class 'conpyguration.types.UNDEFINED'>,
# 'default': 1,
# 'description': <class 'conpyguration.types.UNDEFINED'>,
# 'choices': <class 'conpyguration.types.UNDEFINED'>
# }
# },
# 'return_spec': {
# 'value_type': <class 'int'>,
# 'description': <class 'conpyguration.types.UNDEFINED'>
# }
# }
Functions with docstrings
def my_function(a: int, b: int=1) -> int:
"""
This is a function that adds two numbers together.
Args:
a (int): The first number.
b (int, optional): The second number. Defaults to 1.
Returns:
int: The sum of the two numbers.
"""
return a + b
get_conpyguration(my_function)
# {
# 'description': 'This is a function that adds two numbers together.',
# 'module_name': '__main__',
# 'function_name': 'my_function',
# 'arguments': {
# 'a': {
# 'value_type': <class 'int'>,
# 'default': <class 'conpyguration.types.UNDEFINED'>,
# 'description': 'The first number.',
# 'choices': <class 'conpyguration.types.UNDEFINED'>
# },
# 'b': {
# 'value_type': <class 'int'>,
# 'default': 1,
# 'description': 'The second number. Defaults to 1.',
# 'choices': <class 'conpyguration.types.UNDEFINED'>
# }
# },
# 'return_spec': {
# 'value_type': <class 'int'>,
# 'description': 'The sum of the two numbers.'
# }
# }
Functions with Union types
from typing import Union
def my_function(a: Union[int, float]):
return
get_conpyguration(my_function)
# {
# 'description': <class 'conpyguration.types.UNDEFINED'>,
# 'module_name': '__main__',
# 'function_name': 'my_function',
# 'arguments': {
# 'a': {
# 'value_type': (<class 'int'>, <class 'float'>),
# 'default': <class 'conpyguration.types.UNDEFINED'>,
# 'description': <class 'conpyguration.types.UNDEFINED'>,
# 'choices': <class 'conpyguration.types.UNDEFINED'>
# }
# },
# 'return_spec': <class 'conpyguration.types.UNDEFINED'>
# }
Functions with Literal types (choice)
from typing import Literal
def my_function(a: Literal[1, 2, 3]):
return
get_conpyguration(my_function)
# {
# 'description': <class 'conpyguration.types.UNDEFINED'>,
# 'module_name': '__main__',
# 'function_name': 'my_function',
# 'arguments': {
# 'a': {
# 'value_type': typing.Literal,
# 'default': <class 'conpyguration.types.UNDEFINED'>,
# 'description': <class 'conpyguration.types.UNDEFINED'>,
# 'choices': (1, 2, 3)
# }
# },
# 'return_spec': <class 'conpyguration.types.UNDEFINED'>
# }
Class
from conpyguration import get_class_conpyguration
class MyClass:
"""My Sample Class
Args:
a (int): The first number.
b (int, optional): The second number. Defaults to 1.
"""
def __init__(self, a: int, b: int=1):
self.a = a
self.b = b
def add(self) -> int:
"""Add the two numbers together.
Returns:
int: The sum of the two numbers.
"""
return self.a + self.b
get_class_conpyguration(MyClass)
# {
# 'description': 'My Sample Class',
# 'module_name': '__main__',
# 'class_name': 'MyClass',
# 'init_arguments': {
# 'a': {
# 'value_type': <class 'int'>,
# 'default': <class 'conpyguration.types.UNDEFINED'>,
# 'description': 'The first number.',
# 'choices': <class 'conpyguration.types.UNDEFINED'>
# },
# 'b': {
# 'value_type': <class 'int'>,
# 'default': 1,
# 'description': 'The second number. Defaults to 1.',
# 'choices': <class 'conpyguration.types.UNDEFINED'>
# }
# },
# 'methods': {
# 'add': {
# 'description': 'Add the two numbers together.',
# 'module_name': '__main__',
# 'function_name': 'MyClass.add',
# 'arguments': {},
# 'return_spec': {
# 'value_type': <class 'int'>,
# 'description': 'The sum of the two numbers.'
# }
# }
# }
# }
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
conpyguration-0.1.0.tar.gz
(3.3 kB
view details)
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 conpyguration-0.1.0.tar.gz.
File metadata
- Download URL: conpyguration-0.1.0.tar.gz
- Upload date:
- Size: 3.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.9.21
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dbb0e140206b73a337117f00550f92c4aafc13dc88b939ff84371539aaa12008
|
|
| MD5 |
f51a771dfa60fa4bbfcc6ece39290f2a
|
|
| BLAKE2b-256 |
5aa1f67d966f232c5afda6c835a58dc31d0859205aa715b5bbeb662d1b2d9acc
|
File details
Details for the file conpyguration-0.1.0-py3-none-any.whl.
File metadata
- Download URL: conpyguration-0.1.0-py3-none-any.whl
- Upload date:
- Size: 4.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.9.21
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
60c66a6e2b2ac568256e74e2a2ceaf4773518a5d6af4b0af1dc16452f8c38be8
|
|
| MD5 |
87756281aaea1e49f27c4d66c5dac9c9
|
|
| BLAKE2b-256 |
5b7e3889f92fd94892c6c20413add93d11814cc98f40cc8f7bba8c69810ccb2f
|