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.1.tar.gz
.
File metadata
- Download URL: strapi_api_sdk-0.2.1.tar.gz
- Upload date:
- Size: 6.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.18
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7569b2ebd9366b19587cc1ba0715b7793c43d437f005e38d2f5604e158fc402f |
|
MD5 | 6b52ad15f111a8605524d4efb2749583 |
|
BLAKE2b-256 | cff0ef086051d5567e0bb9a7bb507434d1a663a248aa643ff635a1d8359bf02d |
File details
Details for the file strapi_api_sdk-0.2.1-py3-none-any.whl
.
File metadata
- Download URL: strapi_api_sdk-0.2.1-py3-none-any.whl
- Upload date:
- Size: 9.1 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 | 4cb3abab17a72039ecd4379a07ccac31669a56dc3a74d80479e7939ac25b47a2 |
|
MD5 | 9f714aa1f50970950c62e01a16ad3b45 |
|
BLAKE2b-256 | e55b399226b1f2e5bf03c90110d7c5117cf741de7a3bd8ca5250c1b1be965c5b |