privatefunc


Nameprivatefunc JSON
Version 1.6.23 PyPI version JSON
download
home_page
SummaryCreate private functions in Python
upload_time2023-01-10 19:45:49
maintainer
docs_urlNone
author
requires_python>=3.7
license
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            <h1 align="center">Private Function in Python</h1>
<p align="center"><i>"A smarter way to create private functions in python"</i><p>
  
<h2 align="center">from <a href="https://faheem41.github.io" target="_blank" rel="noreferrer">FAHEEM41</br></a></h2>


<p>
  <ul>
    <li>version: <strong>1.5.23</strong></li>
    <li>first published in: <strong><a href="https://www.sololearn.com" target="_blank" rel="noreferrer">Sololearn</a></strong></li>
    <li>Github first publishing date: <strong>23rd July, 2022</strong></li>
    <li>Last Updated: <strong>11th January, 2023</strong></li>
  </ul>
</p>
</br>

<p>
<h2>Why use the code?</h2>
Let's start with the concept of private functions. Private functions are functions that are only accessible inside the declared module, no other function from any other module can access it.</br>
This project mainly focuses on the security issues of a code. This enables a way to restrict code from accessing other functions from other modules that were not meant to be accessed. And thus, it ensures that only non-private functions i.e. public functions can be accessed from anywhere outside the code.</br></br>
Here's an example, suppose a module has two functions: <i>add()</i> and <i>main()</i>. <i>main()</i> function is meant to run and can be called from other modules. On the other hand, the <i>add()</i> function is a function that is only called by the <i>main()</i> function, and we want to keep this function private, i.e. ensure that it cannot be accessed or called from any other module.
</p>
</br>

<p>
<h2>Understanding the code</h2>
Here we have implemented a very naive idea to get our work done. We have used a <i>decorator</i> which will check whether the function is a private or public function and thereby deny or grant access respectively. The <i>decorator</i> will run, as usual, with the function called, and before the function ran.</br>
For details understanding, have a look at the <a href="https://github.com/Faheem41/Private-Function-in-Python/blob/main/src/privatefunc.py" rel="noreferrer">privatefunc.py</a> file; the documentation of the code, along with how the code is working is given inside the source code.
</p>
</br>

<p>
<h2>How to use the code? (using pip)</h2>
In terminal type the command: <code>pip install privatefunc</code></br>
Add this lines in your module: </br><code>from privatefunc import PrivateFunc</code></br><code>private = PrivateFunc("nameOfThisModuleHere").private</code></br>
Now add <code>@private</code> before the function you want to make private</br></br>
For better understanding have a look at <a href="https://github.com/Faheem41/Private-Function-in-Python/blob/main/test/moduleWithPrivateFunc.py" rel="noreferrer">moduleWithPrivateFunc.py</a>
</p>
</br>

Everything put together:
```
# example.py
from privatefunc import PrivateFunc
private = PrivateFunc("example").private

@private
def hello():
    pass
```

<p>
<h2>Sample Code</h2>
Go through <a href="https://github.com/Faheem41/Private-Function-in-Python/tree/main/test" rel="noreferrer">the demo code</a> to completely understand the insights of the source.
</p>
</br>


<h6 align="center">© 2021-2023 Md. Faheem Hossain fmhossain2941@gmail.com</h6>

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "privatefunc",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": "",
    "keywords": "",
    "author": "",
    "author_email": "\"Md. Faheem Hossain\" <fmhossain2941@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/3c/08/66381acafbf87b6a642b0cf0b2db4382f33cbd385a2096166b207613d4f6/privatefunc-1.6.23.tar.gz",
    "platform": null,
    "description": "<h1 align=\"center\">Private Function in Python</h1>\r\n<p align=\"center\"><i>\"A smarter way to create private functions in python\"</i><p>\r\n  \r\n<h2 align=\"center\">from <a href=\"https://faheem41.github.io\" target=\"_blank\" rel=\"noreferrer\">FAHEEM41</br></a></h2>\r\n\r\n\r\n<p>\r\n  <ul>\r\n    <li>version: <strong>1.5.23</strong></li>\r\n    <li>first published in: <strong><a href=\"https://www.sololearn.com\" target=\"_blank\" rel=\"noreferrer\">Sololearn</a></strong></li>\r\n    <li>Github first publishing date: <strong>23rd July, 2022</strong></li>\r\n    <li>Last Updated: <strong>11th January, 2023</strong></li>\r\n  </ul>\r\n</p>\r\n</br>\r\n\r\n<p>\r\n<h2>Why use the code?</h2>\r\nLet's start with the concept of private functions. Private functions are functions that are only accessible inside the declared module, no other function from any other module can access it.</br>\r\nThis project mainly focuses on the security issues of a code. This enables a way to restrict code from accessing other functions from other modules that were not meant to be accessed. And thus, it ensures that only non-private functions i.e. public functions can be accessed from anywhere outside the code.</br></br>\r\nHere's an example, suppose a module has two functions: <i>add()</i> and <i>main()</i>. <i>main()</i> function is meant to run and can be called from other modules. On the other hand, the <i>add()</i> function is a function that is only called by the <i>main()</i> function, and we want to keep this function private, i.e. ensure that it cannot be accessed or called from any other module.\r\n</p>\r\n</br>\r\n\r\n<p>\r\n<h2>Understanding the code</h2>\r\nHere we have implemented a very naive idea to get our work done. We have used a <i>decorator</i> which will check whether the function is a private or public function and thereby deny or grant access respectively. The <i>decorator</i> will run, as usual, with the function called, and before the function ran.</br>\r\nFor details understanding, have a look at the <a href=\"https://github.com/Faheem41/Private-Function-in-Python/blob/main/src/privatefunc.py\" rel=\"noreferrer\">privatefunc.py</a> file; the documentation of the code, along with how the code is working is given inside the source code.\r\n</p>\r\n</br>\r\n\r\n<p>\r\n<h2>How to use the code? (using pip)</h2>\r\nIn terminal type the command: <code>pip install privatefunc</code></br>\r\nAdd this lines in your module: </br><code>from privatefunc import PrivateFunc</code></br><code>private = PrivateFunc(\"nameOfThisModuleHere\").private</code></br>\r\nNow add <code>@private</code> before the function you want to make private</br></br>\r\nFor better understanding have a look at <a href=\"https://github.com/Faheem41/Private-Function-in-Python/blob/main/test/moduleWithPrivateFunc.py\" rel=\"noreferrer\">moduleWithPrivateFunc.py</a>\r\n</p>\r\n</br>\r\n\r\nEverything put together:\r\n```\r\n# example.py\r\nfrom privatefunc import PrivateFunc\r\nprivate = PrivateFunc(\"example\").private\r\n\r\n@private\r\ndef hello():\r\n    pass\r\n```\r\n\r\n<p>\r\n<h2>Sample Code</h2>\r\nGo through <a href=\"https://github.com/Faheem41/Private-Function-in-Python/tree/main/test\" rel=\"noreferrer\">the demo code</a> to completely understand the insights of the source.\r\n</p>\r\n</br>\r\n\r\n\r\n<h6 align=\"center\">\u00a9 2021-2023 Md. Faheem Hossain fmhossain2941@gmail.com</h6>\r\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "Create private functions in Python",
    "version": "1.6.23",
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "919e4ecb61364aeda48e58082f5c6b959225e5eac6383e4fa17fe78290eae6ff",
                "md5": "b6a6a126b39bab1996fdec6f3ee91ede",
                "sha256": "ca243cad9722a51cf61f8639e52772b524de4e98ec5d0be0883eb0d07688e423"
            },
            "downloads": -1,
            "filename": "privatefunc-1.6.23-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "b6a6a126b39bab1996fdec6f3ee91ede",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 5085,
            "upload_time": "2023-01-10T19:45:47",
            "upload_time_iso_8601": "2023-01-10T19:45:47.860830Z",
            "url": "https://files.pythonhosted.org/packages/91/9e/4ecb61364aeda48e58082f5c6b959225e5eac6383e4fa17fe78290eae6ff/privatefunc-1.6.23-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "3c0866381acafbf87b6a642b0cf0b2db4382f33cbd385a2096166b207613d4f6",
                "md5": "312edfd04da0cd7409d43a71f9519f20",
                "sha256": "735485f05b495a45d33b44f74746161d9114da12f1fe827697c455944c4cd938"
            },
            "downloads": -1,
            "filename": "privatefunc-1.6.23.tar.gz",
            "has_sig": false,
            "md5_digest": "312edfd04da0cd7409d43a71f9519f20",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 4829,
            "upload_time": "2023-01-10T19:45:49",
            "upload_time_iso_8601": "2023-01-10T19:45:49.795304Z",
            "url": "https://files.pythonhosted.org/packages/3c/08/66381acafbf87b6a642b0cf0b2db4382f33cbd385a2096166b207613d4f6/privatefunc-1.6.23.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-01-10 19:45:49",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "lcname": "privatefunc"
}
        
Elapsed time: 0.02606s