Skip to main content
# PyChecko [![Build Status](https://travis-ci.org/viniciusfeitosa/pychecko.svg?branch=master)](https://travis-ci.org/viniciusfeitosa/pychecko)

The PyChecko is a MicroFramework to compose a instance in execution time by rules predefined.

# Example:

There are some [examples](example/).

# Installation:

```
pip install pychecko
```

# Getting started

Inside the directory application...

## Defining class to be used

Our example has two modules, the `app.py` and the `lib.py`.
Inside the `lib.py` there is a method to apply over a class.

```python
# lib.py
def bar(self):
self.email = 'john.doe@email.com'
```

Inside the `app.py` there are a method to apply over the class instance too.
Take a look in the code comments to understand the logic

```python
# app.py
import lib # inside lib has a method bar with the attribute email definition
from pychecko import Pychecko


# There is another method bar with a different definition to the attribute email
def bar(self):
self.email = 'bar@email.com'


# Class A definition
class A:
def __init__(self, first_name, last_name):
# There are just two attributes
self.first_name = first_name
self.last_name = last_name

# And just the method foo
def foo(self):
print('{first_name} {last_name}: {email}'.format(
first_name=self.first_name,
last_name=self.last_name,
email=self.email)) # There is a attribute that is defined just in the bar


# the main logic
if __name__ == '__main__':
# Instantiate the class A
a = A('FirstName', 'LastName')
# pass the instance variable to PyChecko
pycheck = Pychecko(a)
# Add the methods that you want apply
pycheck.add(
bar,
[a.first_name == 'FirstName', a.last_name == 'LastName'] # Two bool conditions
)
pycheck.add(
lib.bar,
[a.first_name != 'FirstName' or a.last_name != 'LastName'] # One bool condition
)

# running PyChecko and get the modified instance
a = pycheck.execute

a.bar()
a.foo() # The result will be: FirstName LastName: 'bar@email.com'
```

## Pychecko with bulk insert

```python
# app.py
from pychecko import Pychecko


# Method bar definition outside the class
def bar(self):
self.email = 'bar@email.com'


# Method foo definition outside the class
def foo(self):
print('{first_name} {last_name}: {email}'.format(
first_name=self.first_name,
last_name=self.last_name,
email=self.email)) # attribute that is defined just in the bar


# Class A definition
class A:
def __init__(self, first_name, last_name):
# There are just two attributes
self.first_name = first_name
self.last_name = last_name


# the main logic
if __name__ == '__main__':
# Instantiate the class A
a = A('FirstName', 'LastName')
# pass the instance variable to PyChecko
pycheck = Pychecko(a)

# Add the methods that you want apply

# Two bool conditions
pycheck.bulk_add(
[
bar,
foo,
]
[True]
)

# running PyChecko and get the modified instance
a = pycheck.execute

a.bar()
a.foo() # The result is: FirstName LastName: 'bar@email.com'
```

## Pychecko Using Classes

```python
from pychecko import PycheckoComponent

# Creating a pycheko component
class MyComponentA(PycheckoComponent):

# is_applied is required for the PychecoComponents
# It's responsible to identify if all class methods
# should be applied in an instance
def is_applied(self):
return True

def bar(self):
self.email = 'john.doe@email.com'


class MyComponentB(PycheckoComponent):

def is_applied(self):
return True

def name_changer(self):
self.first_name = 'john doe'
```

```python
# app.py
import lib # inside lib has a method bar with the attribute email definition
from pychecko import PycheckoClassModifier


# There is another method bar with a different
# definition to the attribute email
def bar(self):
self.email = 'bar@email.com'


# Class A definition
class A:
def __init__(self, first_name, last_name):
# There are just two attributes
self.first_name = first_name
self.last_name = last_name

# And just the method foo
def foo(self):
print('{first_name} {last_name}: {email}'.format(
first_name=self.first_name,
last_name=self.last_name,
email=self.email)) # attribute that is defined just in the bar


# the main logic
if __name__ == '__main__':
# Instantiate the class A
instance = A('FirstName', 'LastName')
# pass the instance variable to PyCheckoClassModifier
# whit the classes that should be applied
pycheck = PycheckoClassModifier(instance, [
lib.MyComponentA(), # This implements bar()
lib.MyComponentB(), # This implements name_changer()
])

# running PyChecko and get the modified instance
a = pycheck.execute

a.bar()
a.name_changer()
a.foo() # The result is: John Doe LastName: 'bar@email.com'

```

## Applying instance validation

Another possible option is validate the instance integrity.

```python
# app.py

'''
create a list with the name methods that must be
in the instance after execute the Pychecko
'''
instance_signature [
'method_a',
'method_b',
'method_c',
]

# In the Pychecko declaration, send the list in the optional parameter
a = A('value1', 'value2')
pycheck = Pychecko(a, signature=instance_signature)
# ...

'''
At final, if all methods that you sent in the list
to Pychecko are in the instance, the instance will be returned
using the `execute` property.

If the instance does't respect the signature will the thrown the
Exception InvalidSignatureClassError
'''
a = pycheck.execute

# ...
```

# Next Features

* Check signature at method level

Metadata

Release files for PyChecko 1.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for PyChecko 1.3.0
File Size Uploaded
PyChecko-1.3.0.tar.gz 5.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for PyChecko 1.3.0
File Interpreter ABI Platform
PyChecko-1.3.0-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 11.8 kB

Release files / PyChecko-1.3.0.tar.gz

Download URL PyChecko-1.3.0.tar.gz
Size 5.4 kB
Tags Source
SHA-256 checksum
How to use checksums
b9e963e9b274e93fde391487231a95ac1dec4fcc323eaff42f992971c1e3785b
BLAKE2b-256 checksum
How to use checksums
1337f591c7bbe9f7bafc6a72502229906f62ca68b0c1f79791a367ae2cdb3d0b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / PyChecko-1.3.0-py2.py3-none-any.whl

Download URL PyChecko-1.3.0-py2.py3-none-any.whl
Size 6.4 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
3c80f7c8e1dbf4b0e0175b35b8daadb9b4c333c8cdf31af1c00b5dd57225a696
BLAKE2b-256 checksum
How to use checksums
fc535d6a661abaa827824fa96f675e81b29818ab6bbfe21fb3ec53c7914ba50f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

1.3.0 This release

2 release files

1.2.0

2 release files

1.1.1

2 release files

1.1.0

2 release files

1.0.1

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page