alfred-python 0.0.1__py3-none-any.whl
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.
- alfred_python-0.0.1.dist-info/LICENSE +19 -0
- alfred_python-0.0.1.dist-info/METADATA +42 -0
- alfred_python-0.0.1.dist-info/RECORD +12 -0
- alfred_python-0.0.1.dist-info/WHEEL +5 -0
- alfred_python-0.0.1.dist-info/top_level.txt +1 -0
- app/__init__.py +24 -0
- app/config/__init__.py +1 -0
- app/config/settings.py +21 -0
- app/typings/__init__.py +1 -0
- app/typings/misc.py +11 -0
- app/utils/__init__.py +1 -0
- app/utils/logging.py +73 -0
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
Copyright (c) 2018 The Python Packaging Authority
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
5
|
+
in the Software without restriction, including without limitation the rights
|
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
8
|
+
furnished to do so, subject to the following conditions:
|
|
9
|
+
|
|
10
|
+
The above copyright notice and this permission notice shall be included in all
|
|
11
|
+
copies or substantial portions of the Software.
|
|
12
|
+
|
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
19
|
+
SOFTWARE.
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: alfred-python
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: Python library designed to simplify and streamline interactions with the Alfred API
|
|
5
|
+
Author-email: Tagshelf LLC <support@tagshelf.com>
|
|
6
|
+
Project-URL: Homepage, https://github.com/tagshelfsrl/alfred-python
|
|
7
|
+
Classifier: Programming Language :: Python :: 3
|
|
8
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
9
|
+
Classifier: Operating System :: OS Independent
|
|
10
|
+
Requires-Python: >=3.8
|
|
11
|
+
Description-Content-Type: text/markdown
|
|
12
|
+
License-File: LICENSE
|
|
13
|
+
|
|
14
|
+
## [Python Application Name]
|
|
15
|
+
|
|
16
|
+
[Application description]
|
|
17
|
+
|
|
18
|
+
## Prerequisites
|
|
19
|
+
|
|
20
|
+
- Python v3.8+
|
|
21
|
+
|
|
22
|
+
## Running the application
|
|
23
|
+
|
|
24
|
+
1. Create a new python environment. We normally use Anaconda, but you can use any python environment manager you want.
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
conda create -n <python environment name> python=3.8
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
2. Install dependencies using `pip`. This project depends on private hosted packages, so you have to setup a `.pypirc`.
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
pip install -r requirements.txt
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
3. Create a dotenv file based on the `dot.env` file (do NOT update the `dot.env`, copy it and rename it `.env`).
|
|
37
|
+
|
|
38
|
+
4. Run the worker
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
python run.py
|
|
42
|
+
```
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
app/__init__.py,sha256=zEZFxt99UXKz2zXAkpHqpsgy0-P-iskF8cm27LGB9P8,511
|
|
2
|
+
app/config/__init__.py,sha256=fEyRT6_hrTaf31KF64NmlsdNQWvr14lRm0UUqV16qto,41
|
|
3
|
+
app/config/settings.py,sha256=ajTTlKuxiDeD71VXYuxNKXt2eYQ_DkQpL1ZHoHEPUok,639
|
|
4
|
+
app/typings/__init__.py,sha256=p0EkRS5iJdU7e5esdVgwTavsOEdAWZFVwNzsGSBJtck,31
|
|
5
|
+
app/typings/misc.py,sha256=Rurk9DUtUfGSWGG9frSlVnrqZ5q_XkBDFNDgY6_eMeU,194
|
|
6
|
+
app/utils/__init__.py,sha256=4mYTDUdXO5hZnrC3Jywdn0S1SGqDVxNpyWI9XZ0-Yf0,32
|
|
7
|
+
app/utils/logging.py,sha256=AZLe0rsG6xXPddhnpIw4bl79U595MjdbOxL93iAIdyI,2271
|
|
8
|
+
alfred_python-0.0.1.dist-info/LICENSE,sha256=2bm9uFabQZ3Ykb_SaSU_uUbAj2-htc6WJQmS_65qD00,1073
|
|
9
|
+
alfred_python-0.0.1.dist-info/METADATA,sha256=33KIHL0-xrYOAJOztO7lRMru5oLgv8rIlg2E5RjsW84,1157
|
|
10
|
+
alfred_python-0.0.1.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
|
|
11
|
+
alfred_python-0.0.1.dist-info/top_level.txt,sha256=io9g7LCbfmTG1SFKgEOGXmCFB9uMP2H5lerm0HiHWQE,4
|
|
12
|
+
alfred_python-0.0.1.dist-info/RECORD,,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
app
|
app/__init__.py
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# Native imports
|
|
2
|
+
import logging
|
|
3
|
+
|
|
4
|
+
# Project imports
|
|
5
|
+
from app.config import settings
|
|
6
|
+
from app.utils import init_loggers
|
|
7
|
+
from app.typings import LoggingOptions
|
|
8
|
+
|
|
9
|
+
# Initialize loggers
|
|
10
|
+
loggers = [logging.getLogger(__name__)]
|
|
11
|
+
logging_options: LoggingOptions = {
|
|
12
|
+
"env": settings.env,
|
|
13
|
+
"level": logging.INFO,
|
|
14
|
+
"name": settings.name,
|
|
15
|
+
"papertrail_host": settings.pt_host,
|
|
16
|
+
"papertrail_port": settings.pt_port,
|
|
17
|
+
}
|
|
18
|
+
init_loggers(loggers, logging_options)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def run():
|
|
22
|
+
"""
|
|
23
|
+
Run main application
|
|
24
|
+
"""
|
app/config/__init__.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
from app.config.settings import settings
|
app/config/settings.py
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# 3rd party imports
|
|
2
|
+
from pydantic import Field
|
|
3
|
+
from pydantic_settings import BaseSettings, SettingsConfigDict
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class Settings(BaseSettings):
|
|
7
|
+
# Setup dotenv file support
|
|
8
|
+
model_config = SettingsConfigDict(env_file=".env", env_file_encoding="utf-8")
|
|
9
|
+
|
|
10
|
+
# App configuration
|
|
11
|
+
version: str = Field("0.1.0")
|
|
12
|
+
name: str = Field("python-template")
|
|
13
|
+
env: str = Field("dev", env="ENV")
|
|
14
|
+
health_path: str = Field("./healthy", env="HEALTH_PATH")
|
|
15
|
+
|
|
16
|
+
# Logging configuration
|
|
17
|
+
pt_host: str = Field("logs3.papertrailapp.com", env="PAPERTRAIL_HOST")
|
|
18
|
+
pt_port: int = Field(33780, env="PAPERTRAIL_PORT")
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
settings = Settings()
|
app/typings/__init__.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
from app.typings.misc import *
|
app/typings/misc.py
ADDED
app/utils/__init__.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
from app.utils.logging import *
|
app/utils/logging.py
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
# Native imports
|
|
2
|
+
import json
|
|
3
|
+
import socket
|
|
4
|
+
import logging
|
|
5
|
+
from typing import List, Union
|
|
6
|
+
from logging.handlers import SysLogHandler
|
|
7
|
+
|
|
8
|
+
# Project imports
|
|
9
|
+
from app.typings import LoggingOptions
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def init_loggers(loggers: List[logging.Logger], options: LoggingOptions):
|
|
13
|
+
"""
|
|
14
|
+
Setup a custom logger with JSON formatting and handler
|
|
15
|
+
based on application environment.
|
|
16
|
+
"""
|
|
17
|
+
env = options.get("env")
|
|
18
|
+
name = options.get("name")
|
|
19
|
+
pt_host = options.get("papertrail_host")
|
|
20
|
+
pt_port = options.get("papertrail_port")
|
|
21
|
+
|
|
22
|
+
class ContextFilter(logging.Filter):
|
|
23
|
+
hostname = socket.gethostname()
|
|
24
|
+
|
|
25
|
+
def filter(self, record):
|
|
26
|
+
record.hostname = ContextFilter.hostname
|
|
27
|
+
return True
|
|
28
|
+
|
|
29
|
+
class PapertrailFormatter(logging.Formatter):
|
|
30
|
+
def __init__(
|
|
31
|
+
self,
|
|
32
|
+
fmt: Union[str, None] = ...,
|
|
33
|
+
datefmt: Union[str, None] = ...,
|
|
34
|
+
) -> None:
|
|
35
|
+
super().__init__(datefmt=datefmt)
|
|
36
|
+
|
|
37
|
+
def format(self, record):
|
|
38
|
+
is_text = isinstance(record.msg, (str))
|
|
39
|
+
record.message = record.getMessage() if is_text else record.msg
|
|
40
|
+
record.asctime = self.formatTime(record, self.datefmt)
|
|
41
|
+
record.stack_info = self.formatStack(record.stack_info)
|
|
42
|
+
if record.exc_info:
|
|
43
|
+
if not record.exc_text:
|
|
44
|
+
record.exc_text = self.formatException(record.exc_info)
|
|
45
|
+
|
|
46
|
+
# Prepare json logging
|
|
47
|
+
data = {"msg": record.message, "level": record.levelname}
|
|
48
|
+
if record.exc_text:
|
|
49
|
+
data["exception"] = record.exc_text
|
|
50
|
+
|
|
51
|
+
return f"{record.asctime} {name} {name}-{env} {json.dumps(data)}"
|
|
52
|
+
|
|
53
|
+
# Setup handler based on env
|
|
54
|
+
if options.get("env") == "dev":
|
|
55
|
+
handler = logging.StreamHandler()
|
|
56
|
+
else:
|
|
57
|
+
handler = SysLogHandler(address=(pt_host, pt_port))
|
|
58
|
+
|
|
59
|
+
# Add filter to handler
|
|
60
|
+
handler.addFilter(ContextFilter())
|
|
61
|
+
|
|
62
|
+
# Setup handler formatter
|
|
63
|
+
handler.setFormatter(PapertrailFormatter(datefmt="%b %d %H:%M:%S"))
|
|
64
|
+
|
|
65
|
+
for logger in loggers:
|
|
66
|
+
# Remove all logger existing handlers
|
|
67
|
+
logger.handlers = []
|
|
68
|
+
|
|
69
|
+
# Set logger level
|
|
70
|
+
logger.setLevel(options["level"])
|
|
71
|
+
|
|
72
|
+
# Set logger handler
|
|
73
|
+
logger.addHandler(handler)
|