Interact with Strapi functionalities within your python application, includes the ability to perform create, read, update, and delete (CRUD) operations on existing APIs endpoints and provides an Authenticator class ready to create new users, API Tokens and etc.
Project description
Strapi API SDK
Interact with Strapi functionalities within your python application, includes the ability to perform create, read, update, and delete (CRUD) operations on existing APIs endpoints and provides an Authenticator class ready to create new users, API Tokens and etc.
Instalation
pip install strapi-api-sdk
Usage Example
You can use strapi-api-sdk to:
- Create, update and delete registers on all APIs that your Strapi application provides.
- Create a user inside Strapi with a specific or generic role (public, authenticated, etc).
- Create an API Token to a specific user (using the JWT auth from Strapi's core).
Code example
from strapi_api_sdk.sdk import (
StrapiAuthenticator,
StrapiUser,
StrapiClient
)
BASE_URL = "https://strapi.mybaseurl.com.br"
TOKEN = "my-token-as-string"
# Instantiate clients.
auth = StrapiAuthenticator(base_url=BASE_URL, api_token=TOKEN)
user = StrapiUser(base_url=BASE_URL, auth=auth)
client = StrapiClient(base_url=BASE_URL, auth=auth, request_timeout=800)
# Create a new user
# NOTE: In the absence of password parameter, the class creates a random URL-safe text string, in Base64 encoding and use it as the user password.
new_user = user.register_user(
username="creation-tester2",
email="creation2@tester.com.br",
role_type="authenticated",
)
# Create an API token for this user
new_user_token = auth.create_token(
identifier=new_user["username"],
password=new_user["password"]
)
# Retrieve some data.
api_data = client.get_entries(plural_api_id="api-ids", batch_size=100)
one_api_data = client.get_entry(plural_api_id="api-ids", document_id=1, populate=["*"])
# Create entry.
api_data_to_create_dict = {
"foo": "bar",
"num": 35
}
create_api_data = client.create_entry(plural_api_id="some-apis", data=api_data_to_create_dict)
Happy Coding! :)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file strapi_api_sdk-0.2.0.tar.gz
.
File metadata
- Download URL: strapi_api_sdk-0.2.0.tar.gz
- Upload date:
- Size: 6.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.18
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 59e5315687633cf218e84123f7964c63bb090cbc95b3b4386e200e43d4fe8329 |
|
MD5 | 8f8833b9b2394b9c9090fcd1ab9c7bab |
|
BLAKE2b-256 | 4827891b46fe88eb427bd053159934df59160481ce77c899ae829fa77475dd45 |
File details
Details for the file strapi_api_sdk-0.2.0-py3-none-any.whl
.
File metadata
- Download URL: strapi_api_sdk-0.2.0-py3-none-any.whl
- Upload date:
- Size: 9.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.18
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | bca20f3d9bb607dc859ac0c91e4b4f86255d61e585c3f1f59c63df37fcd512b3 |
|
MD5 | b4afdd452ac4b7939fa8f301dd34459c |
|
BLAKE2b-256 | c89823afc19ff7456368839e2d397e47c1a0ac3e0ea1ac6ff2f9a38a96d57b89 |