helpr 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- helpr-0.1.0/PKG-INFO +204 -0
- helpr-0.1.0/README.rst +189 -0
- helpr-0.1.0/helpr.egg-info/PKG-INFO +204 -0
- helpr-0.1.0/helpr.egg-info/SOURCES.txt +12 -0
- helpr-0.1.0/helpr.egg-info/dependency_links.txt +1 -0
- helpr-0.1.0/helpr.egg-info/requires.txt +18 -0
- helpr-0.1.0/helpr.egg-info/top_level.txt +1 -0
- helpr-0.1.0/setup.cfg +4 -0
- helpr-0.1.0/setup.py +32 -0
- helpr-0.1.0/src/__init__.py +0 -0
- helpr-0.1.0/src/common-utils.py +13 -0
- helpr-0.1.0/src/exceptions.py +6 -0
- helpr-0.1.0/src/format_response.py +20 -0
- helpr-0.1.0/src/secret_manager.py +33 -0
helpr-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: helpr
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A Python package to help you with your daily tasks
|
|
5
|
+
Home-page: https://github.com/clinikally/helpr
|
|
6
|
+
Author: Clinikally
|
|
7
|
+
Author-email: puneetsrivastava@clinikally.com
|
|
8
|
+
License: MIT license
|
|
9
|
+
Platform: UNKNOWN
|
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
|
11
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
12
|
+
Classifier: Operating System :: OS Independent
|
|
13
|
+
Description-Content-Type: text/x-rst
|
|
14
|
+
|
|
15
|
+
Example Package Python
|
|
16
|
+
======================
|
|
17
|
+
|
|
18
|
+
This is a simple python package, providing a template to write your own.
|
|
19
|
+
|
|
20
|
+
A package is a collection of code that aims to perform related tasks, or perform a high level function.
|
|
21
|
+
Python packages contain modules (`.py` files) that can be grouped into any number of sub-packages (folders below the package folder).
|
|
22
|
+
This basic package contains a single module - ``example_module`` - and no sub-packages.
|
|
23
|
+
|
|
24
|
+
Package components are typically imported using one of the following methods:
|
|
25
|
+
|
|
26
|
+
.. code-block:: python
|
|
27
|
+
|
|
28
|
+
import examplepackage
|
|
29
|
+
|
|
30
|
+
examplepackage.example_module.example_function()
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
.. code-block:: python
|
|
34
|
+
|
|
35
|
+
from examplepackage.example_module import example_function
|
|
36
|
+
|
|
37
|
+
example_function()
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
See this `Real Python guide <https://realpython.com/python-modules-packages/>`_ for further information on importing packages and modules.
|
|
41
|
+
|
|
42
|
+
Useful aspects of building a package are summarised below.
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
Setup
|
|
46
|
+
-----
|
|
47
|
+
|
|
48
|
+
There are two key components that distinguish a python packages from folders containing a collection of python files:
|
|
49
|
+
|
|
50
|
+
* `__init__.py` files
|
|
51
|
+
* `setup.py`
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
`__init__.py`
|
|
55
|
+
^^^^^^^^^^^^^
|
|
56
|
+
|
|
57
|
+
An `__init__.py` file allows files (now modules) within the same directory to imported.
|
|
58
|
+
You should include one in each directory of your package that contains python code.
|
|
59
|
+
|
|
60
|
+
You will often find these files empty, but they do have an additional use.
|
|
61
|
+
Code within a `__init__.py` file is executed when the package or sub-package is imported.
|
|
62
|
+
Any objects defined in this file will therefore be available at that level of the package.
|
|
63
|
+
One use for this is importing useful modules, functions or classes from deep within your package stucture, making them accessible from the package level.
|
|
64
|
+
|
|
65
|
+
.. code-block:: python
|
|
66
|
+
|
|
67
|
+
from examplepackage.example_module import example_function
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
With the code above included in the top-level `__init__.py`, ``example_function`` can be accessed by users via simpler import statements:
|
|
71
|
+
|
|
72
|
+
.. code-block:: python
|
|
73
|
+
|
|
74
|
+
import examplepackage
|
|
75
|
+
|
|
76
|
+
examplepackage.another_function()
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
.. code-block:: python
|
|
80
|
+
|
|
81
|
+
from examplepackage import another_function
|
|
82
|
+
|
|
83
|
+
another_function()
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
`setup.py`
|
|
88
|
+
^^^^^^^^^^
|
|
89
|
+
|
|
90
|
+
This file sits outside of the folder containing your package code.
|
|
91
|
+
It contains the instructions that the ``setuptools`` library uses to build and install your package.
|
|
92
|
+
These are provided using the ``setup`` function, including:
|
|
93
|
+
|
|
94
|
+
* author and/or maintainer contact details
|
|
95
|
+
* the folders to install, or use ``setuptools.find_packages()``
|
|
96
|
+
* ``install_requires`` - other packages that this package depends on
|
|
97
|
+
* classifiers that describe the required major python version and operating system - this is necessary for uploading a package to PyPI
|
|
98
|
+
|
|
99
|
+
For detailed usage of ``setup()`` see the ``setuptools`` `documentation <https://setuptools.readthedocs.io/en/latest/setuptools.html#developer-s-guide>`_.
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
Installing your package
|
|
103
|
+
-----------------------
|
|
104
|
+
|
|
105
|
+
Packages can only be imported if they are located in a directory on the PYTHONPATH (which you can view in python using ``sys.path()``).
|
|
106
|
+
|
|
107
|
+
Packages installed using the command line tool ``pip`` are added to this path.
|
|
108
|
+
This is preferable to manually adding paths to ``sys.path`` in your scripts.
|
|
109
|
+
You can install local packages that you are working on in develop mode, by pointing pip the **directory** that contains `setup.py` and your package folder:
|
|
110
|
+
|
|
111
|
+
.. code-block:: console
|
|
112
|
+
|
|
113
|
+
pip install -e local_path/example-package-python
|
|
114
|
+
|
|
115
|
+
This creates a temporary reference to your local package files - you'll see an `.egg-info` file has been created next to your package.
|
|
116
|
+
When packages are installed without the ``-e`` flag, they're installed in `site-packages` next to your python installation.
|
|
117
|
+
|
|
118
|
+
Be sure to uninstall your package once you've finished - don't delete the `.egg-info` reference.
|
|
119
|
+
Use the name of the package when deleting it, like so:
|
|
120
|
+
|
|
121
|
+
.. code-block:: console
|
|
122
|
+
|
|
123
|
+
pip uninstall examplepackage
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
Documentation
|
|
127
|
+
-------------
|
|
128
|
+
|
|
129
|
+
A README is a good place to provide an overview of your package or project.
|
|
130
|
+
This README is written in reStructuredText (`.rst`) for easy integration with the main documentation.
|
|
131
|
+
However, Markdown and many other markup languages work just as well.
|
|
132
|
+
|
|
133
|
+
The `sphinx package <https://www.sphinx-doc.org/en/master/usage/quickstart.html>`_ is very useful for generating detailed package documentation, and can generate this from inline documentation in your code.
|
|
134
|
+
Once installed, the ``sphinx-quickstart`` command can be used to set up your documentation.
|
|
135
|
+
You might find the ``autosummary`` `extension <https://www.sphinx-doc.org/en/master/usage/extensions/autosummary.html>`_ useful for extracting documentation from entire modules.
|
|
136
|
+
Documentation usually sits inside the package, in a `docs/` folder.
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
Dependencies
|
|
140
|
+
------------
|
|
141
|
+
|
|
142
|
+
You should list packages that your package uses in the `requirements.txt` file.
|
|
143
|
+
Listing your package depencencies ensures that these packages are also installed when someone installs your package.
|
|
144
|
+
Explicitly stating versions of dependencies can increase the reproducibility in the function of your package that might depend on particular versions of other packages.
|
|
145
|
+
|
|
146
|
+
Python package dependencies can indicate minimum package versions (``>=``) or the exact version number (``==``) that is required.
|
|
147
|
+
|
|
148
|
+
.. code-block:: txt
|
|
149
|
+
|
|
150
|
+
pandas==1.0.0
|
|
151
|
+
numpy>=1.18.4
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
License
|
|
155
|
+
-------
|
|
156
|
+
|
|
157
|
+
It's important to let users and developers know under what circumstance they can use, modify and redistribute your code.
|
|
158
|
+
|
|
159
|
+
The ``LICENSE`` file associated with your package should contain the text for the packages license.
|
|
160
|
+
The example in this package is for the MIT license.
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
Versioning
|
|
164
|
+
----------
|
|
165
|
+
|
|
166
|
+
A version number is essential for releasing your package.
|
|
167
|
+
`Semantic versioning <https://semver.org/>`_ is a useful method for informative versioning.
|
|
168
|
+
|
|
169
|
+
It can be useful to store this in a separate file, so that it can be referenced from multiple places (e.g. ``setup.py`` and the main documentation).
|
|
170
|
+
|
|
171
|
+
`Git tagging <https://drive.google.com/drive/folders/1CJj28JmAOG5IQY_DzQDtFVosg60VpjNs?usp=sharing>`_ can be used to mark significant points in your projects development.
|
|
172
|
+
These tags can also be used to trigger version releases, for example using `GitHub Actions <https://github.com/marketplace/actions/tag-release-on-push-action>`_.
|
|
173
|
+
|
|
174
|
+
Including Other Files
|
|
175
|
+
---------------------
|
|
176
|
+
|
|
177
|
+
You may want to include example data or other non-python files in your package.
|
|
178
|
+
Be aware that the documentation for including non-python files is `notoriously bad <https://stackoverflow.com/a/14159430/8103477>`_, as most methods have been depreciated.
|
|
179
|
+
|
|
180
|
+
To include data in your source and binary distributions:
|
|
181
|
+
|
|
182
|
+
* In the ``setup.py`` file ``setup(...)`` function call, include ``include_package_data = True``.
|
|
183
|
+
* Alongside your `setup.py` file, provide a `MANIFEST.in` file.
|
|
184
|
+
|
|
185
|
+
The ``MANIFEST.in`` file should list any non-python files that you wish to include distributions.
|
|
186
|
+
|
|
187
|
+
A ``MANIFEST.in`` file includes single files, or all files of a type, as below:
|
|
188
|
+
|
|
189
|
+
.. code-block:: txt
|
|
190
|
+
|
|
191
|
+
include README.rst
|
|
192
|
+
recursive-include examplepackage/examples *.csv
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
Distributing
|
|
196
|
+
------------
|
|
197
|
+
|
|
198
|
+
Storing your source code in an open repository allows others to view and critique your code. Python code can be distributed in a number of formats, as described by this `overview of python packages <https://packaging.python.org/overview/>`_.
|
|
199
|
+
|
|
200
|
+
To allow others to install and use your code more easily, consider uploading your package to the Python Package Index (PyPI).
|
|
201
|
+
PyPI is an online repository of python packages and is the default repository used by ``pip``.
|
|
202
|
+
|
|
203
|
+
Please see this `guide to packaging projects <https://packaging.python.org/tutorials/packaging-projects/>`_ for instructions on uploading your package to PyPI.
|
|
204
|
+
|
helpr-0.1.0/README.rst
ADDED
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
Example Package Python
|
|
2
|
+
======================
|
|
3
|
+
|
|
4
|
+
This is a simple python package, providing a template to write your own.
|
|
5
|
+
|
|
6
|
+
A package is a collection of code that aims to perform related tasks, or perform a high level function.
|
|
7
|
+
Python packages contain modules (`.py` files) that can be grouped into any number of sub-packages (folders below the package folder).
|
|
8
|
+
This basic package contains a single module - ``example_module`` - and no sub-packages.
|
|
9
|
+
|
|
10
|
+
Package components are typically imported using one of the following methods:
|
|
11
|
+
|
|
12
|
+
.. code-block:: python
|
|
13
|
+
|
|
14
|
+
import examplepackage
|
|
15
|
+
|
|
16
|
+
examplepackage.example_module.example_function()
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
.. code-block:: python
|
|
20
|
+
|
|
21
|
+
from examplepackage.example_module import example_function
|
|
22
|
+
|
|
23
|
+
example_function()
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
See this `Real Python guide <https://realpython.com/python-modules-packages/>`_ for further information on importing packages and modules.
|
|
27
|
+
|
|
28
|
+
Useful aspects of building a package are summarised below.
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
Setup
|
|
32
|
+
-----
|
|
33
|
+
|
|
34
|
+
There are two key components that distinguish a python packages from folders containing a collection of python files:
|
|
35
|
+
|
|
36
|
+
* `__init__.py` files
|
|
37
|
+
* `setup.py`
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
`__init__.py`
|
|
41
|
+
^^^^^^^^^^^^^
|
|
42
|
+
|
|
43
|
+
An `__init__.py` file allows files (now modules) within the same directory to imported.
|
|
44
|
+
You should include one in each directory of your package that contains python code.
|
|
45
|
+
|
|
46
|
+
You will often find these files empty, but they do have an additional use.
|
|
47
|
+
Code within a `__init__.py` file is executed when the package or sub-package is imported.
|
|
48
|
+
Any objects defined in this file will therefore be available at that level of the package.
|
|
49
|
+
One use for this is importing useful modules, functions or classes from deep within your package stucture, making them accessible from the package level.
|
|
50
|
+
|
|
51
|
+
.. code-block:: python
|
|
52
|
+
|
|
53
|
+
from examplepackage.example_module import example_function
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
With the code above included in the top-level `__init__.py`, ``example_function`` can be accessed by users via simpler import statements:
|
|
57
|
+
|
|
58
|
+
.. code-block:: python
|
|
59
|
+
|
|
60
|
+
import examplepackage
|
|
61
|
+
|
|
62
|
+
examplepackage.another_function()
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
.. code-block:: python
|
|
66
|
+
|
|
67
|
+
from examplepackage import another_function
|
|
68
|
+
|
|
69
|
+
another_function()
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
`setup.py`
|
|
74
|
+
^^^^^^^^^^
|
|
75
|
+
|
|
76
|
+
This file sits outside of the folder containing your package code.
|
|
77
|
+
It contains the instructions that the ``setuptools`` library uses to build and install your package.
|
|
78
|
+
These are provided using the ``setup`` function, including:
|
|
79
|
+
|
|
80
|
+
* author and/or maintainer contact details
|
|
81
|
+
* the folders to install, or use ``setuptools.find_packages()``
|
|
82
|
+
* ``install_requires`` - other packages that this package depends on
|
|
83
|
+
* classifiers that describe the required major python version and operating system - this is necessary for uploading a package to PyPI
|
|
84
|
+
|
|
85
|
+
For detailed usage of ``setup()`` see the ``setuptools`` `documentation <https://setuptools.readthedocs.io/en/latest/setuptools.html#developer-s-guide>`_.
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
Installing your package
|
|
89
|
+
-----------------------
|
|
90
|
+
|
|
91
|
+
Packages can only be imported if they are located in a directory on the PYTHONPATH (which you can view in python using ``sys.path()``).
|
|
92
|
+
|
|
93
|
+
Packages installed using the command line tool ``pip`` are added to this path.
|
|
94
|
+
This is preferable to manually adding paths to ``sys.path`` in your scripts.
|
|
95
|
+
You can install local packages that you are working on in develop mode, by pointing pip the **directory** that contains `setup.py` and your package folder:
|
|
96
|
+
|
|
97
|
+
.. code-block:: console
|
|
98
|
+
|
|
99
|
+
pip install -e local_path/example-package-python
|
|
100
|
+
|
|
101
|
+
This creates a temporary reference to your local package files - you'll see an `.egg-info` file has been created next to your package.
|
|
102
|
+
When packages are installed without the ``-e`` flag, they're installed in `site-packages` next to your python installation.
|
|
103
|
+
|
|
104
|
+
Be sure to uninstall your package once you've finished - don't delete the `.egg-info` reference.
|
|
105
|
+
Use the name of the package when deleting it, like so:
|
|
106
|
+
|
|
107
|
+
.. code-block:: console
|
|
108
|
+
|
|
109
|
+
pip uninstall examplepackage
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
Documentation
|
|
113
|
+
-------------
|
|
114
|
+
|
|
115
|
+
A README is a good place to provide an overview of your package or project.
|
|
116
|
+
This README is written in reStructuredText (`.rst`) for easy integration with the main documentation.
|
|
117
|
+
However, Markdown and many other markup languages work just as well.
|
|
118
|
+
|
|
119
|
+
The `sphinx package <https://www.sphinx-doc.org/en/master/usage/quickstart.html>`_ is very useful for generating detailed package documentation, and can generate this from inline documentation in your code.
|
|
120
|
+
Once installed, the ``sphinx-quickstart`` command can be used to set up your documentation.
|
|
121
|
+
You might find the ``autosummary`` `extension <https://www.sphinx-doc.org/en/master/usage/extensions/autosummary.html>`_ useful for extracting documentation from entire modules.
|
|
122
|
+
Documentation usually sits inside the package, in a `docs/` folder.
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
Dependencies
|
|
126
|
+
------------
|
|
127
|
+
|
|
128
|
+
You should list packages that your package uses in the `requirements.txt` file.
|
|
129
|
+
Listing your package depencencies ensures that these packages are also installed when someone installs your package.
|
|
130
|
+
Explicitly stating versions of dependencies can increase the reproducibility in the function of your package that might depend on particular versions of other packages.
|
|
131
|
+
|
|
132
|
+
Python package dependencies can indicate minimum package versions (``>=``) or the exact version number (``==``) that is required.
|
|
133
|
+
|
|
134
|
+
.. code-block:: txt
|
|
135
|
+
|
|
136
|
+
pandas==1.0.0
|
|
137
|
+
numpy>=1.18.4
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
License
|
|
141
|
+
-------
|
|
142
|
+
|
|
143
|
+
It's important to let users and developers know under what circumstance they can use, modify and redistribute your code.
|
|
144
|
+
|
|
145
|
+
The ``LICENSE`` file associated with your package should contain the text for the packages license.
|
|
146
|
+
The example in this package is for the MIT license.
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
Versioning
|
|
150
|
+
----------
|
|
151
|
+
|
|
152
|
+
A version number is essential for releasing your package.
|
|
153
|
+
`Semantic versioning <https://semver.org/>`_ is a useful method for informative versioning.
|
|
154
|
+
|
|
155
|
+
It can be useful to store this in a separate file, so that it can be referenced from multiple places (e.g. ``setup.py`` and the main documentation).
|
|
156
|
+
|
|
157
|
+
`Git tagging <https://drive.google.com/drive/folders/1CJj28JmAOG5IQY_DzQDtFVosg60VpjNs?usp=sharing>`_ can be used to mark significant points in your projects development.
|
|
158
|
+
These tags can also be used to trigger version releases, for example using `GitHub Actions <https://github.com/marketplace/actions/tag-release-on-push-action>`_.
|
|
159
|
+
|
|
160
|
+
Including Other Files
|
|
161
|
+
---------------------
|
|
162
|
+
|
|
163
|
+
You may want to include example data or other non-python files in your package.
|
|
164
|
+
Be aware that the documentation for including non-python files is `notoriously bad <https://stackoverflow.com/a/14159430/8103477>`_, as most methods have been depreciated.
|
|
165
|
+
|
|
166
|
+
To include data in your source and binary distributions:
|
|
167
|
+
|
|
168
|
+
* In the ``setup.py`` file ``setup(...)`` function call, include ``include_package_data = True``.
|
|
169
|
+
* Alongside your `setup.py` file, provide a `MANIFEST.in` file.
|
|
170
|
+
|
|
171
|
+
The ``MANIFEST.in`` file should list any non-python files that you wish to include distributions.
|
|
172
|
+
|
|
173
|
+
A ``MANIFEST.in`` file includes single files, or all files of a type, as below:
|
|
174
|
+
|
|
175
|
+
.. code-block:: txt
|
|
176
|
+
|
|
177
|
+
include README.rst
|
|
178
|
+
recursive-include examplepackage/examples *.csv
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
Distributing
|
|
182
|
+
------------
|
|
183
|
+
|
|
184
|
+
Storing your source code in an open repository allows others to view and critique your code. Python code can be distributed in a number of formats, as described by this `overview of python packages <https://packaging.python.org/overview/>`_.
|
|
185
|
+
|
|
186
|
+
To allow others to install and use your code more easily, consider uploading your package to the Python Package Index (PyPI).
|
|
187
|
+
PyPI is an online repository of python packages and is the default repository used by ``pip``.
|
|
188
|
+
|
|
189
|
+
Please see this `guide to packaging projects <https://packaging.python.org/tutorials/packaging-projects/>`_ for instructions on uploading your package to PyPI.
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: helpr
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A Python package to help you with your daily tasks
|
|
5
|
+
Home-page: https://github.com/clinikally/helpr
|
|
6
|
+
Author: Clinikally
|
|
7
|
+
Author-email: puneetsrivastava@clinikally.com
|
|
8
|
+
License: MIT license
|
|
9
|
+
Platform: UNKNOWN
|
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
|
11
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
12
|
+
Classifier: Operating System :: OS Independent
|
|
13
|
+
Description-Content-Type: text/x-rst
|
|
14
|
+
|
|
15
|
+
Example Package Python
|
|
16
|
+
======================
|
|
17
|
+
|
|
18
|
+
This is a simple python package, providing a template to write your own.
|
|
19
|
+
|
|
20
|
+
A package is a collection of code that aims to perform related tasks, or perform a high level function.
|
|
21
|
+
Python packages contain modules (`.py` files) that can be grouped into any number of sub-packages (folders below the package folder).
|
|
22
|
+
This basic package contains a single module - ``example_module`` - and no sub-packages.
|
|
23
|
+
|
|
24
|
+
Package components are typically imported using one of the following methods:
|
|
25
|
+
|
|
26
|
+
.. code-block:: python
|
|
27
|
+
|
|
28
|
+
import examplepackage
|
|
29
|
+
|
|
30
|
+
examplepackage.example_module.example_function()
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
.. code-block:: python
|
|
34
|
+
|
|
35
|
+
from examplepackage.example_module import example_function
|
|
36
|
+
|
|
37
|
+
example_function()
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
See this `Real Python guide <https://realpython.com/python-modules-packages/>`_ for further information on importing packages and modules.
|
|
41
|
+
|
|
42
|
+
Useful aspects of building a package are summarised below.
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
Setup
|
|
46
|
+
-----
|
|
47
|
+
|
|
48
|
+
There are two key components that distinguish a python packages from folders containing a collection of python files:
|
|
49
|
+
|
|
50
|
+
* `__init__.py` files
|
|
51
|
+
* `setup.py`
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
`__init__.py`
|
|
55
|
+
^^^^^^^^^^^^^
|
|
56
|
+
|
|
57
|
+
An `__init__.py` file allows files (now modules) within the same directory to imported.
|
|
58
|
+
You should include one in each directory of your package that contains python code.
|
|
59
|
+
|
|
60
|
+
You will often find these files empty, but they do have an additional use.
|
|
61
|
+
Code within a `__init__.py` file is executed when the package or sub-package is imported.
|
|
62
|
+
Any objects defined in this file will therefore be available at that level of the package.
|
|
63
|
+
One use for this is importing useful modules, functions or classes from deep within your package stucture, making them accessible from the package level.
|
|
64
|
+
|
|
65
|
+
.. code-block:: python
|
|
66
|
+
|
|
67
|
+
from examplepackage.example_module import example_function
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
With the code above included in the top-level `__init__.py`, ``example_function`` can be accessed by users via simpler import statements:
|
|
71
|
+
|
|
72
|
+
.. code-block:: python
|
|
73
|
+
|
|
74
|
+
import examplepackage
|
|
75
|
+
|
|
76
|
+
examplepackage.another_function()
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
.. code-block:: python
|
|
80
|
+
|
|
81
|
+
from examplepackage import another_function
|
|
82
|
+
|
|
83
|
+
another_function()
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
`setup.py`
|
|
88
|
+
^^^^^^^^^^
|
|
89
|
+
|
|
90
|
+
This file sits outside of the folder containing your package code.
|
|
91
|
+
It contains the instructions that the ``setuptools`` library uses to build and install your package.
|
|
92
|
+
These are provided using the ``setup`` function, including:
|
|
93
|
+
|
|
94
|
+
* author and/or maintainer contact details
|
|
95
|
+
* the folders to install, or use ``setuptools.find_packages()``
|
|
96
|
+
* ``install_requires`` - other packages that this package depends on
|
|
97
|
+
* classifiers that describe the required major python version and operating system - this is necessary for uploading a package to PyPI
|
|
98
|
+
|
|
99
|
+
For detailed usage of ``setup()`` see the ``setuptools`` `documentation <https://setuptools.readthedocs.io/en/latest/setuptools.html#developer-s-guide>`_.
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
Installing your package
|
|
103
|
+
-----------------------
|
|
104
|
+
|
|
105
|
+
Packages can only be imported if they are located in a directory on the PYTHONPATH (which you can view in python using ``sys.path()``).
|
|
106
|
+
|
|
107
|
+
Packages installed using the command line tool ``pip`` are added to this path.
|
|
108
|
+
This is preferable to manually adding paths to ``sys.path`` in your scripts.
|
|
109
|
+
You can install local packages that you are working on in develop mode, by pointing pip the **directory** that contains `setup.py` and your package folder:
|
|
110
|
+
|
|
111
|
+
.. code-block:: console
|
|
112
|
+
|
|
113
|
+
pip install -e local_path/example-package-python
|
|
114
|
+
|
|
115
|
+
This creates a temporary reference to your local package files - you'll see an `.egg-info` file has been created next to your package.
|
|
116
|
+
When packages are installed without the ``-e`` flag, they're installed in `site-packages` next to your python installation.
|
|
117
|
+
|
|
118
|
+
Be sure to uninstall your package once you've finished - don't delete the `.egg-info` reference.
|
|
119
|
+
Use the name of the package when deleting it, like so:
|
|
120
|
+
|
|
121
|
+
.. code-block:: console
|
|
122
|
+
|
|
123
|
+
pip uninstall examplepackage
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
Documentation
|
|
127
|
+
-------------
|
|
128
|
+
|
|
129
|
+
A README is a good place to provide an overview of your package or project.
|
|
130
|
+
This README is written in reStructuredText (`.rst`) for easy integration with the main documentation.
|
|
131
|
+
However, Markdown and many other markup languages work just as well.
|
|
132
|
+
|
|
133
|
+
The `sphinx package <https://www.sphinx-doc.org/en/master/usage/quickstart.html>`_ is very useful for generating detailed package documentation, and can generate this from inline documentation in your code.
|
|
134
|
+
Once installed, the ``sphinx-quickstart`` command can be used to set up your documentation.
|
|
135
|
+
You might find the ``autosummary`` `extension <https://www.sphinx-doc.org/en/master/usage/extensions/autosummary.html>`_ useful for extracting documentation from entire modules.
|
|
136
|
+
Documentation usually sits inside the package, in a `docs/` folder.
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
Dependencies
|
|
140
|
+
------------
|
|
141
|
+
|
|
142
|
+
You should list packages that your package uses in the `requirements.txt` file.
|
|
143
|
+
Listing your package depencencies ensures that these packages are also installed when someone installs your package.
|
|
144
|
+
Explicitly stating versions of dependencies can increase the reproducibility in the function of your package that might depend on particular versions of other packages.
|
|
145
|
+
|
|
146
|
+
Python package dependencies can indicate minimum package versions (``>=``) or the exact version number (``==``) that is required.
|
|
147
|
+
|
|
148
|
+
.. code-block:: txt
|
|
149
|
+
|
|
150
|
+
pandas==1.0.0
|
|
151
|
+
numpy>=1.18.4
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
License
|
|
155
|
+
-------
|
|
156
|
+
|
|
157
|
+
It's important to let users and developers know under what circumstance they can use, modify and redistribute your code.
|
|
158
|
+
|
|
159
|
+
The ``LICENSE`` file associated with your package should contain the text for the packages license.
|
|
160
|
+
The example in this package is for the MIT license.
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
Versioning
|
|
164
|
+
----------
|
|
165
|
+
|
|
166
|
+
A version number is essential for releasing your package.
|
|
167
|
+
`Semantic versioning <https://semver.org/>`_ is a useful method for informative versioning.
|
|
168
|
+
|
|
169
|
+
It can be useful to store this in a separate file, so that it can be referenced from multiple places (e.g. ``setup.py`` and the main documentation).
|
|
170
|
+
|
|
171
|
+
`Git tagging <https://drive.google.com/drive/folders/1CJj28JmAOG5IQY_DzQDtFVosg60VpjNs?usp=sharing>`_ can be used to mark significant points in your projects development.
|
|
172
|
+
These tags can also be used to trigger version releases, for example using `GitHub Actions <https://github.com/marketplace/actions/tag-release-on-push-action>`_.
|
|
173
|
+
|
|
174
|
+
Including Other Files
|
|
175
|
+
---------------------
|
|
176
|
+
|
|
177
|
+
You may want to include example data or other non-python files in your package.
|
|
178
|
+
Be aware that the documentation for including non-python files is `notoriously bad <https://stackoverflow.com/a/14159430/8103477>`_, as most methods have been depreciated.
|
|
179
|
+
|
|
180
|
+
To include data in your source and binary distributions:
|
|
181
|
+
|
|
182
|
+
* In the ``setup.py`` file ``setup(...)`` function call, include ``include_package_data = True``.
|
|
183
|
+
* Alongside your `setup.py` file, provide a `MANIFEST.in` file.
|
|
184
|
+
|
|
185
|
+
The ``MANIFEST.in`` file should list any non-python files that you wish to include distributions.
|
|
186
|
+
|
|
187
|
+
A ``MANIFEST.in`` file includes single files, or all files of a type, as below:
|
|
188
|
+
|
|
189
|
+
.. code-block:: txt
|
|
190
|
+
|
|
191
|
+
include README.rst
|
|
192
|
+
recursive-include examplepackage/examples *.csv
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
Distributing
|
|
196
|
+
------------
|
|
197
|
+
|
|
198
|
+
Storing your source code in an open repository allows others to view and critique your code. Python code can be distributed in a number of formats, as described by this `overview of python packages <https://packaging.python.org/overview/>`_.
|
|
199
|
+
|
|
200
|
+
To allow others to install and use your code more easily, consider uploading your package to the Python Package Index (PyPI).
|
|
201
|
+
PyPI is an online repository of python packages and is the default repository used by ``pip``.
|
|
202
|
+
|
|
203
|
+
Please see this `guide to packaging projects <https://packaging.python.org/tutorials/packaging-projects/>`_ for instructions on uploading your package to PyPI.
|
|
204
|
+
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
README.rst
|
|
2
|
+
setup.py
|
|
3
|
+
helpr.egg-info/PKG-INFO
|
|
4
|
+
helpr.egg-info/SOURCES.txt
|
|
5
|
+
helpr.egg-info/dependency_links.txt
|
|
6
|
+
helpr.egg-info/requires.txt
|
|
7
|
+
helpr.egg-info/top_level.txt
|
|
8
|
+
src/__init__.py
|
|
9
|
+
src/common-utils.py
|
|
10
|
+
src/exceptions.py
|
|
11
|
+
src/format_response.py
|
|
12
|
+
src/secret_manager.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
annotated-types==0.7.0
|
|
2
|
+
anyio==4.7.0
|
|
3
|
+
boto3==1.35.81
|
|
4
|
+
botocore==1.35.81
|
|
5
|
+
exceptiongroup==1.2.2
|
|
6
|
+
fastapi==0.115.6
|
|
7
|
+
idna==3.10
|
|
8
|
+
jmespath==1.0.1
|
|
9
|
+
phonenumbers==8.13.52
|
|
10
|
+
pydantic==2.10.3
|
|
11
|
+
pydantic_core==2.27.1
|
|
12
|
+
python-dateutil==2.9.0.post0
|
|
13
|
+
s3transfer==0.10.4
|
|
14
|
+
six==1.17.0
|
|
15
|
+
sniffio==1.3.1
|
|
16
|
+
starlette==0.41.3
|
|
17
|
+
typing_extensions==4.12.2
|
|
18
|
+
urllib3==1.26.20
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
src
|
helpr-0.1.0/setup.cfg
ADDED
helpr-0.1.0/setup.py
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
from setuptools import setup, find_packages
|
|
2
|
+
|
|
3
|
+
def read_requirements(file):
|
|
4
|
+
with open(file) as f:
|
|
5
|
+
return f.read().splitlines()
|
|
6
|
+
|
|
7
|
+
def read_file(file):
|
|
8
|
+
with open(file) as f:
|
|
9
|
+
return f.read()
|
|
10
|
+
|
|
11
|
+
long_description = read_file("README.rst")
|
|
12
|
+
version = read_file("VERSION")
|
|
13
|
+
requirements = read_requirements("requirements.txt")
|
|
14
|
+
|
|
15
|
+
setup(
|
|
16
|
+
name = 'helpr',
|
|
17
|
+
version = version,
|
|
18
|
+
author = 'Clinikally',
|
|
19
|
+
author_email = 'puneetsrivastava@clinikally.com',
|
|
20
|
+
url = 'https://github.com/clinikally/helpr',
|
|
21
|
+
description = 'A Python package to help you with your daily tasks',
|
|
22
|
+
long_description_content_type = "text/x-rst", # If this causes a warning, upgrade your setuptools package
|
|
23
|
+
long_description = long_description,
|
|
24
|
+
license = "MIT license",
|
|
25
|
+
packages = find_packages(exclude=["test"]), # Don't include test directory in binary distribution
|
|
26
|
+
install_requires = requirements,
|
|
27
|
+
classifiers=[
|
|
28
|
+
"Programming Language :: Python :: 3",
|
|
29
|
+
"License :: OSI Approved :: MIT License",
|
|
30
|
+
"Operating System :: OS Independent",
|
|
31
|
+
]
|
|
32
|
+
)
|
|
File without changes
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import phonenumbers
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
def validate_mobile(mobile):
|
|
5
|
+
if not mobile or not mobile.startswith('+') or not mobile[1:].isdigit():
|
|
6
|
+
return False
|
|
7
|
+
try:
|
|
8
|
+
x = phonenumbers.parse(mobile, 'IN') # Default region set to 'IN'
|
|
9
|
+
if not phonenumbers.is_valid_number_for_region(x,'IN'):
|
|
10
|
+
return False
|
|
11
|
+
except phonenumbers.phonenumberutil.NumberParseException:
|
|
12
|
+
return False
|
|
13
|
+
return True
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
from typing import Optional, Union
|
|
2
|
+
from fastapi.responses import JSONResponse
|
|
3
|
+
from fastapi import status as HTTPStatus
|
|
4
|
+
|
|
5
|
+
def create_response(data: dict, message: str, status: str, status_code: int, error_code: Optional[int] = None) -> JSONResponse:
|
|
6
|
+
return JSONResponse(
|
|
7
|
+
content={
|
|
8
|
+
"data": data,
|
|
9
|
+
"message": message,
|
|
10
|
+
"status": status,
|
|
11
|
+
"error_code": error_code
|
|
12
|
+
},
|
|
13
|
+
status_code=status_code
|
|
14
|
+
)
|
|
15
|
+
|
|
16
|
+
def jsonify_success(data: Optional[Union[dict, list]] = None, message: Optional[str] = None, status_code: int = 200):
|
|
17
|
+
return create_response(data=data if data else {}, message=message, status="success", status_code=status_code)
|
|
18
|
+
|
|
19
|
+
def jsonify_failure(data: Optional[Union[dict, list]] = None, message: Optional[str] = None, error_code: Optional[int] = None, status_code: int = 400):
|
|
20
|
+
return create_response(data=data if data else {}, message=message, status="failed", status_code=status_code, error_code=error_code)
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import boto3
|
|
2
|
+
from botocore.exceptions import ClientError
|
|
3
|
+
import json
|
|
4
|
+
|
|
5
|
+
class SecretManager:
|
|
6
|
+
|
|
7
|
+
def __init__(self, secret_name, region_name):
|
|
8
|
+
self.secret_name = secret_name
|
|
9
|
+
self._cached_secrets = None
|
|
10
|
+
self._region_name = region_name
|
|
11
|
+
|
|
12
|
+
def fetch_secrets(self):
|
|
13
|
+
# Create a Secrets Manager client
|
|
14
|
+
session = boto3.session.Session()
|
|
15
|
+
client = session.client(
|
|
16
|
+
service_name='secretsmanager',
|
|
17
|
+
region_name=self._region_name
|
|
18
|
+
)
|
|
19
|
+
|
|
20
|
+
try:
|
|
21
|
+
get_secret_value_response = client.get_secret_value(
|
|
22
|
+
SecretId=self.secret_name
|
|
23
|
+
)
|
|
24
|
+
except ClientError as e:
|
|
25
|
+
raise e
|
|
26
|
+
|
|
27
|
+
secret = get_secret_value_response['SecretString']
|
|
28
|
+
return json.loads(secret)
|
|
29
|
+
|
|
30
|
+
def load_secrets(self):
|
|
31
|
+
if self._cached_secrets is None:
|
|
32
|
+
self._cached_secrets = self.fetch_secrets()
|
|
33
|
+
return self._cached_secrets
|