respectify 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.
@@ -0,0 +1,207 @@
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[codz]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ .Python
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ .eggs/
17
+ lib/
18
+ lib64/
19
+ parts/
20
+ sdist/
21
+ var/
22
+ wheels/
23
+ share/python-wheels/
24
+ *.egg-info/
25
+ .installed.cfg
26
+ *.egg
27
+ MANIFEST
28
+
29
+ # PyInstaller
30
+ # Usually these files are written by a python script from a template
31
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
32
+ *.manifest
33
+ *.spec
34
+
35
+ # Installer logs
36
+ pip-log.txt
37
+ pip-delete-this-directory.txt
38
+
39
+ # Unit test / coverage reports
40
+ htmlcov/
41
+ .tox/
42
+ .nox/
43
+ .coverage
44
+ .coverage.*
45
+ .cache
46
+ nosetests.xml
47
+ coverage.xml
48
+ *.cover
49
+ *.py.cover
50
+ .hypothesis/
51
+ .pytest_cache/
52
+ cover/
53
+
54
+ # Translations
55
+ *.mo
56
+ *.pot
57
+
58
+ # Django stuff:
59
+ *.log
60
+ local_settings.py
61
+ db.sqlite3
62
+ db.sqlite3-journal
63
+
64
+ # Flask stuff:
65
+ instance/
66
+ .webassets-cache
67
+
68
+ # Scrapy stuff:
69
+ .scrapy
70
+
71
+ # Sphinx documentation
72
+ docs/_build/
73
+
74
+ # PyBuilder
75
+ .pybuilder/
76
+ target/
77
+
78
+ # Jupyter Notebook
79
+ .ipynb_checkpoints
80
+
81
+ # IPython
82
+ profile_default/
83
+ ipython_config.py
84
+
85
+ # pyenv
86
+ # For a library or package, you might want to ignore these files since the code is
87
+ # intended to run in multiple environments; otherwise, check them in:
88
+ # .python-version
89
+
90
+ # pipenv
91
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
93
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
94
+ # install all needed dependencies.
95
+ #Pipfile.lock
96
+
97
+ # UV
98
+ # Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
99
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
100
+ # commonly ignored for libraries.
101
+ #uv.lock
102
+
103
+ # poetry
104
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
105
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
106
+ # commonly ignored for libraries.
107
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
108
+ #poetry.lock
109
+ #poetry.toml
110
+
111
+ # pdm
112
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
113
+ # pdm recommends including project-wide configuration in pdm.toml, but excluding .pdm-python.
114
+ # https://pdm-project.org/en/latest/usage/project/#working-with-version-control
115
+ #pdm.lock
116
+ #pdm.toml
117
+ .pdm-python
118
+ .pdm-build/
119
+
120
+ # pixi
121
+ # Similar to Pipfile.lock, it is generally recommended to include pixi.lock in version control.
122
+ #pixi.lock
123
+ # Pixi creates a virtual environment in the .pixi directory, just like venv module creates one
124
+ # in the .venv directory. It is recommended not to include this directory in version control.
125
+ .pixi
126
+
127
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
128
+ __pypackages__/
129
+
130
+ # Celery stuff
131
+ celerybeat-schedule
132
+ celerybeat.pid
133
+
134
+ # SageMath parsed files
135
+ *.sage.py
136
+
137
+ # Environments
138
+ .env
139
+ .envrc
140
+ .venv
141
+ env/
142
+ venv/
143
+ ENV/
144
+ env.bak/
145
+ venv.bak/
146
+
147
+ # Spyder project settings
148
+ .spyderproject
149
+ .spyproject
150
+
151
+ # Rope project settings
152
+ .ropeproject
153
+
154
+ # mkdocs documentation
155
+ /site
156
+
157
+ # mypy
158
+ .mypy_cache/
159
+ .dmypy.json
160
+ dmypy.json
161
+
162
+ # Pyre type checker
163
+ .pyre/
164
+
165
+ # pytype static type analyzer
166
+ .pytype/
167
+
168
+ # Cython debug symbols
169
+ cython_debug/
170
+
171
+ # PyCharm
172
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
173
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
174
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
175
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
176
+ #.idea/
177
+
178
+ # Abstra
179
+ # Abstra is an AI-powered process automation framework.
180
+ # Ignore directories containing user credentials, local state, and settings.
181
+ # Learn more at https://abstra.io/docs
182
+ .abstra/
183
+
184
+ # Visual Studio Code
185
+ # Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore
186
+ # that can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
187
+ # and can be added to the global gitignore or merged into this file. However, if you prefer,
188
+ # you could uncomment the following to ignore the entire vscode folder
189
+ # .vscode/
190
+
191
+ # Ruff stuff:
192
+ .ruff_cache/
193
+
194
+ # PyPI configuration file
195
+ .pypirc
196
+
197
+ # Cursor
198
+ # Cursor is an AI-powered code editor. `.cursorignore` specifies files/directories to
199
+ # exclude from AI features like autocomplete and code analysis. Recommended for sensitive data
200
+ # refer to https://docs.cursor.com/context/ignore-files
201
+ .cursorignore
202
+ .cursorindexingignore
203
+
204
+ # Marimo
205
+ marimo/_static/
206
+ marimo/_lsp/
207
+ __marimo__/
@@ -0,0 +1,290 @@
1
+ Metadata-Version: 2.4
2
+ Name: respectify
3
+ Version: 0.1.0
4
+ Summary: Python client library for the Respectify API
5
+ Project-URL: Homepage, https://respectify.ai
6
+ Project-URL: Documentation, https://docs.respectify.org
7
+ Project-URL: Repository, https://github.com/respectify/respectify-python
8
+ Project-URL: Issues, https://github.com/respectify/respectify-python/issues
9
+ Author-email: Respectify <dave@respectify.ai>
10
+ License-Expression: MIT
11
+ Keywords: abuse-detection,api,civility,comment,content-filtering,discourse,discussion,dogwhistle,moderation,respectify,spam,toxicity
12
+ Classifier: Development Status :: 4 - Beta
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: Intended Audience :: System Administrators
15
+ Classifier: License :: OSI Approved :: MIT License
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Programming Language :: Python :: 3.9
18
+ Classifier: Programming Language :: Python :: 3.10
19
+ Classifier: Programming Language :: Python :: 3.11
20
+ Classifier: Programming Language :: Python :: 3.12
21
+ Classifier: Topic :: Communications
22
+ Classifier: Topic :: Internet :: WWW/HTTP :: Dynamic Content
23
+ Classifier: Topic :: Internet :: WWW/HTTP :: Site Management
24
+ Classifier: Topic :: Security
25
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
26
+ Classifier: Topic :: Text Processing :: Filters
27
+ Classifier: Topic :: Text Processing :: Linguistic
28
+ Classifier: Typing :: Typed
29
+ Requires-Python: >=3.9
30
+ Requires-Dist: beartype>=0.15.0
31
+ Requires-Dist: httpx>=0.24.0
32
+ Requires-Dist: pydantic>=2.0.0
33
+ Requires-Dist: typing-extensions>=4.0.0
34
+ Provides-Extra: dev
35
+ Requires-Dist: pre-commit>=3.0.0; extra == 'dev'
36
+ Requires-Dist: pytest-asyncio>=0.21.0; extra == 'dev'
37
+ Requires-Dist: pytest>=7.0.0; extra == 'dev'
38
+ Requires-Dist: python-dotenv>=1.0.0; extra == 'dev'
39
+ Requires-Dist: ruff>=0.0.280; extra == 'dev'
40
+ Provides-Extra: docs
41
+ Requires-Dist: myst-parser>=2.0.0; extra == 'docs'
42
+ Requires-Dist: sphinx-autodoc-typehints>=1.24.0; extra == 'docs'
43
+ Requires-Dist: sphinx-rtd-theme>=1.3.0; extra == 'docs'
44
+ Requires-Dist: sphinx>=7.0.0; extra == 'docs'
45
+ Description-Content-Type: text/markdown
46
+
47
+ # Respectify Python Client
48
+
49
+ [![PyPI version](https://badge.fury.io/py/respectify.svg)](https://badge.fury.io/py/respectify)
50
+ [![Python 3.9+](https://img.shields.io/badge/python-3.9+-blue.svg)](https://www.python.org/downloads/)
51
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
52
+
53
+ A Python client library for the [Respectify API](https://respectify.ai), providing both synchronous and asynchronous interfaces for comment moderation, spam detection, toxicity analysis, and dogwhistle detection.
54
+
55
+ ## Features
56
+
57
+ - **🔄 Dual Interface**: Both synchronous (`RespectifyClient`) and asynchronous (`RespectifyAsyncClient`) clients
58
+ - **🛡️ Type Safety**: Full type hints with Pydantic schema validation
59
+ - **📊 Comprehensive**: All Respectify API endpoints supported
60
+ - **⚡ Efficient**: Megacall support for multiple analyses in single requests
61
+ - **🚨 Error Handling**: Custom exception classes for different API error conditions
62
+ - **🐍 Modern Python**: Uses httpx for HTTP requests, beartype for runtime type checking
63
+
64
+ ## Installation
65
+
66
+ ```bash
67
+ pip install respectify
68
+ ```
69
+
70
+ ## Quick Start
71
+
72
+ ### Synchronous Client
73
+
74
+ ```python
75
+ from respectify import RespectifyClient
76
+
77
+ # Initialize client
78
+ client = RespectifyClient(
79
+ email="your-email@example.com",
80
+ api_key="your-api-key"
81
+ )
82
+
83
+ # Initialize a topic
84
+ topic = client.init_topic_from_text("This is my article content")
85
+ article_id = topic.article_id
86
+
87
+ # Check if a comment is spam
88
+ spam_result = client.check_spam("Great post!", article_id)
89
+ print(f"Is spam: {spam_result.is_spam}")
90
+
91
+ # Evaluate comment quality and toxicity
92
+ score = client.evaluate_comment("This is a thoughtful comment", article_id)
93
+ print(f"Quality: {score.overall_score}/5, Toxicity: {score.toxicity_score:.2f}")
94
+ ```
95
+
96
+ ### Asynchronous Client
97
+
98
+ ```python
99
+ import asyncio
100
+ from respectify import RespectifyAsyncClient
101
+
102
+ async def main():
103
+ client = RespectifyAsyncClient(
104
+ email="your-email@example.com",
105
+ api_key="your-api-key"
106
+ )
107
+
108
+ # Initialize topic
109
+ topic = await client.init_topic_from_text("Article content")
110
+ article_id = topic.article_id
111
+
112
+ # Run multiple analyses concurrently
113
+ spam_task = client.check_spam("Great post!", article_id)
114
+ score_task = client.evaluate_comment("Thoughtful comment", article_id)
115
+
116
+ spam_result, score_result = await asyncio.gather(spam_task, score_task)
117
+
118
+ print(f"Spam: {spam_result.is_spam}, Quality: {score_result.overall_score}/5")
119
+
120
+ asyncio.run(main())
121
+ ```
122
+
123
+ ### Megacall for Efficiency
124
+
125
+ Perform multiple analyses in a single API call:
126
+
127
+ ```python
128
+ # Instead of multiple separate calls...
129
+ result = client.megacall(
130
+ comment="Test comment",
131
+ article_id=article_id,
132
+ include_spam=True,
133
+ include_relevance=True,
134
+ include_comment_score=True,
135
+ include_dogwhistle=True
136
+ )
137
+
138
+ # Access individual results
139
+ print(f"Spam: {result.spam.is_spam if result.spam else 'N/A'}")
140
+ print(f"Quality: {result.comment_score.overall_score if result.comment_score else 'N/A'}/5")
141
+ print(f"On topic: {result.relevance.on_topic.is_on_topic if result.relevance else 'N/A'}")
142
+ print(f"Dogwhistles: {result.dogwhistle.detection.dogwhistles_detected if result.dogwhistle else 'N/A'}")
143
+ ```
144
+
145
+ ## API Reference
146
+
147
+ ### Available Methods
148
+
149
+ **Topic Management:**
150
+ - `init_topic_from_text(text, topic_description=None)` - Initialize topic from text content
151
+ - `init_topic_from_url(url, topic_description=None)` - Initialize topic from URL
152
+
153
+ **Comment Analysis:**
154
+ - `check_spam(comment, article_id)` - Spam detection
155
+ - `evaluate_comment(comment, article_id)` - Quality scoring and toxicity analysis
156
+ - `check_relevance(comment, article_id, banned_topics=None)` - Relevance and banned topic detection
157
+ - `check_dogwhistle(comment, sensitive_topics=None, dogwhistle_examples=None)` - Dogwhistle detection
158
+
159
+ **Batch Operations:**
160
+ - `megacall(comment, article_id, **options)` - Multiple analyses in one call
161
+
162
+ **Authentication:**
163
+ - `check_user_credentials()` - Verify API credentials
164
+
165
+ ### Response Schemas
166
+
167
+ All API responses are parsed into strongly-typed Pydantic models:
168
+
169
+ - `InitTopicResponse` - Topic initialization result
170
+ - `SpamDetectionResult` - Spam analysis with confidence scores
171
+ - `CommentScore` - Quality metrics and toxicity analysis
172
+ - `CommentRelevanceResult` - Topic relevance and banned topic detection
173
+ - `DogwhistleResult` - Dogwhistle detection with detailed analysis
174
+ - `MegaCallResult` - Container for multiple analysis results
175
+ - `UserCheckResponse` - Authentication verification result
176
+
177
+ ### Error Handling
178
+
179
+ ```python
180
+ from respectify import (
181
+ RespectifyError, # Base exception
182
+ AuthenticationError, # Invalid credentials (401)
183
+ BadRequestError, # Invalid parameters (400)
184
+ PaymentRequiredError, # Subscription required (402)
185
+ ServerError # Server issues (500+)
186
+ )
187
+
188
+ try:
189
+ result = client.check_spam("test", article_id)
190
+ except AuthenticationError:
191
+ print("Please check your API credentials")
192
+ except PaymentRequiredError:
193
+ print("This feature requires a paid plan")
194
+ except BadRequestError as e:
195
+ print(f"Invalid request: {e.message}")
196
+ ```
197
+
198
+ ## Configuration
199
+
200
+ ### Environment Variables
201
+
202
+ Create a `.env` file for testing:
203
+
204
+ ```bash
205
+ RESPECTIFY_EMAIL=your-email@example.com
206
+ RESPECTIFY_API_KEY=your-api-key
207
+ RESPECTIFY_BASE_URL=https://app.respectify.org # Optional
208
+ REAL_ARTICLE_ID=your-test-article-uuid # Optional
209
+ ```
210
+
211
+ ### Client Options
212
+
213
+ ```python
214
+ client = RespectifyClient(
215
+ email="your-email@example.com",
216
+ api_key="your-api-key",
217
+ base_url="https://app.respectify.org", # Optional, defaults to production
218
+ version="0.2", # Optional, API version
219
+ timeout=30.0 # Optional, request timeout in seconds
220
+ )
221
+ ```
222
+
223
+ ## Development
224
+
225
+ ### Running Tests
226
+
227
+ ```bash
228
+ # Install development dependencies
229
+ pip install -e ".[dev]"
230
+
231
+ # Run tests with real API (requires .env file)
232
+ pytest tests/ -v
233
+
234
+ # Run tests with coverage
235
+ pytest tests/ --cov=respectify --cov-report=html
236
+ ```
237
+
238
+ ### Building Documentation
239
+
240
+ ```bash
241
+ # Install documentation dependencies
242
+ pip install -e ".[docs]"
243
+
244
+ # Build documentation
245
+ cd docs
246
+ make html
247
+
248
+ # Serve documentation locally
249
+ python -m http.server 8000 --directory _build/html
250
+ ```
251
+
252
+ ### Code Quality
253
+
254
+ ```bash
255
+ # Run ruff linting and formatting
256
+ ruff check respectify/
257
+ ruff format respectify/
258
+
259
+ # Beartype provides runtime type checking automatically
260
+ # No separate type checking step needed!
261
+ ```
262
+
263
+ ## Requirements
264
+
265
+ - Python 3.9+
266
+ - httpx >= 0.24.0
267
+ - pydantic >= 2.0.0
268
+ - beartype >= 0.15.0
269
+
270
+ ## License
271
+
272
+ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
273
+
274
+ ## Support
275
+
276
+ - **Documentation**: [Full API documentation](https://docs.respectify.org)
277
+ - **Issues**: [GitHub Issues](https://github.com/respectify/respectify-python/issues)
278
+ - **Website**: [Respectify.ai](https://respectify.ai)
279
+
280
+ ## Changelog
281
+
282
+ ### v0.1.0 (2025-01-XX)
283
+
284
+ - Initial release
285
+ - Synchronous and asynchronous client support
286
+ - Complete API coverage for all Respectify endpoints
287
+ - Comprehensive type safety with Pydantic schemas
288
+ - Megacall support for efficient batch operations
289
+ - Full test suite with real API integration
290
+ - Sphinx documentation with examples