List the wordlists of the organization. The list is paginated.
from moderation_api import ModerationAPI
import os
with ModerationAPI(
secret_key=os.getenv("MODAPI_SECRET_KEY", ""),
) as ma_client:
res = ma_client.wordlist.list(page=1, page_size=20)
while res is not None:
# Handle items
res = res.next()
| Parameter |
Type |
Required |
Description |
page |
Optional[int] |
➖ |
N/A |
page_size |
Optional[int] |
➖ |
N/A |
project_id |
Optional[str] |
➖ |
The project to act on, by ID or name. Required with an organization key unless the key reaches only one project; list projects with GET /projects. A project key acts on its own project and needs no value: naming another one is an error. |
retries |
Optional[utils.RetryConfig] |
➖ |
Configuration to override the default retry behavior of the client. |
models.ListWordlistsResponse
| Error Type |
Status Code |
Content Type |
| errors.BadRequestError |
400 |
application/json |
| errors.AuthenticationError |
401 |
application/json |
| errors.PermissionDeniedError |
403 |
application/json |
| errors.NotFoundError |
404 |
application/json |
| errors.RateLimitError |
429 |
application/json |
| errors.InternalServerError |
500 |
application/json |
| errors.ModerationAPIDefaultError |
4XX, 5XX |
*/* |
Create a wordlist in the organization. You can add words now or later. Each word is embedded in the background for similarity matching. Use the embedding status endpoint to follow the progress. To use the wordlist in moderation, add it to a policy.
from moderation_api import ModerationAPI
import os
with ModerationAPI(
secret_key=os.getenv("MODAPI_SECRET_KEY", ""),
) as ma_client:
res = ma_client.wordlist.create(name="<value>")
# Handle response
print(res)
| Parameter |
Type |
Required |
Description |
name |
str |
✔️ |
Name of the wordlist |
project_id |
Optional[str] |
➖ |
The project to act on, by ID or name. Required with an organization key unless the key reaches only one project; list projects with GET /projects. A project key acts on its own project and needs no value: naming another one is an error. |
key |
Optional[str] |
➖ |
Key of the wordlist. Default: made from the name. If the key is already in use, a suffix is added. |
description |
Optional[str] |
➖ |
Description of the wordlist |
words |
List[str] |
➖ |
Words to add to the wordlist. Words are converted to lowercase. Duplicate and empty words are ignored. Maximum 5000 words. |
retries |
Optional[utils.RetryConfig] |
➖ |
Configuration to override the default retry behavior of the client. |
models.CreateWordlistResponse
| Error Type |
Status Code |
Content Type |
| errors.BadRequestError |
400 |
application/json |
| errors.AuthenticationError |
401 |
application/json |
| errors.RateLimitError |
429 |
application/json |
| errors.ModerationAPIDefaultError |
4XX, 5XX |
*/* |
Get a specific wordlist by ID
from moderation_api import ModerationAPI
import os
with ModerationAPI(
secret_key=os.getenv("MODAPI_SECRET_KEY", ""),
) as ma_client:
res = ma_client.wordlist.retrieve(id="<id>")
# Handle response
print(res)
| Parameter |
Type |
Required |
Description |
id |
str |
✔️ |
ID of the wordlist to get |
project_id |
Optional[str] |
➖ |
The project to act on, by ID or name. Required with an organization key unless the key reaches only one project; list projects with GET /projects. A project key acts on its own project and needs no value: naming another one is an error. |
retries |
Optional[utils.RetryConfig] |
➖ |
Configuration to override the default retry behavior of the client. |
models.GetWordlistResponse
| Error Type |
Status Code |
Content Type |
| errors.BadRequestError |
400 |
application/json |
| errors.AuthenticationError |
401 |
application/json |
| errors.PermissionDeniedError |
403 |
application/json |
| errors.NotFoundError |
404 |
application/json |
| errors.RateLimitError |
429 |
application/json |
| errors.InternalServerError |
500 |
application/json |
| errors.ModerationAPIDefaultError |
4XX, 5XX |
*/* |
Update a wordlist. Fields that you do not send stay the same. If you send words, they replace all existing words, and the embeddings are updated in the background.
from moderation_api import ModerationAPI
import os
with ModerationAPI(
secret_key=os.getenv("MODAPI_SECRET_KEY", ""),
) as ma_client:
res = ma_client.wordlist.update(id="<id>")
# Handle response
print(res)
| Parameter |
Type |
Required |
Description |
id |
str |
✔️ |
ID of the wordlist to update |
project_id |
Optional[str] |
➖ |
The project to act on, by ID or name. Required with an organization key unless the key reaches only one project; list projects with GET /projects. A project key acts on its own project and needs no value: naming another one is an error. |
name |
Optional[str] |
➖ |
New name for the wordlist |
key |
Optional[str] |
➖ |
New key for the wordlist |
description |
Optional[str] |
➖ |
New description for the wordlist |
words |
List[str] |
➖ |
New words for the wordlist. Replace the existing words with these new ones. Words are converted to lowercase. Duplicate and empty words are ignored. Maximum 5000 words. |
strict |
Optional[bool] |
➖ |
Deprecated. Now using threshold in project settings. |
retries |
Optional[utils.RetryConfig] |
➖ |
Configuration to override the default retry behavior of the client. |
models.UpdateWordlistResponse
| Error Type |
Status Code |
Content Type |
| errors.BadRequestError |
400 |
application/json |
| errors.AuthenticationError |
401 |
application/json |
| errors.NotFoundError |
404 |
application/json |
| errors.RateLimitError |
429 |
application/json |
| errors.ModerationAPIDefaultError |
4XX, 5XX |
*/* |
Get the current embedding progress status for a wordlist
from moderation_api import ModerationAPI
import os
with ModerationAPI(
secret_key=os.getenv("MODAPI_SECRET_KEY", ""),
) as ma_client:
res = ma_client.wordlist.get_embedding_status(id="<id>")
# Handle response
print(res)
| Parameter |
Type |
Required |
Description |
id |
str |
✔️ |
ID of the wordlist to check embedding status for |
project_id |
Optional[str] |
➖ |
The project to act on, by ID or name. Required with an organization key unless the key reaches only one project; list projects with GET /projects. A project key acts on its own project and needs no value: naming another one is an error. |
retries |
Optional[utils.RetryConfig] |
➖ |
Configuration to override the default retry behavior of the client. |
models.GetWordlistEmbeddingStatusResponse
| Error Type |
Status Code |
Content Type |
| errors.BadRequestError |
400 |
application/json |
| errors.AuthenticationError |
401 |
application/json |
| errors.PermissionDeniedError |
403 |
application/json |
| errors.NotFoundError |
404 |
application/json |
| errors.RateLimitError |
429 |
application/json |
| errors.InternalServerError |
500 |
application/json |
| errors.ModerationAPIDefaultError |
4XX, 5XX |
*/* |