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
Configuration
Environment variables
To use strapi-api-sdk, you need to set two environment variables:
# ---DOTENV EXAMPLE---
STRAPI_API_TOKEN= # Your API Token
STRAPI_BASE_URL=strapi.mybaseurl.com.br
You can later on change these two env variables if you want to.
For the token change, use StrapiAuthenticator().set_token()
For the base URL change, call the http object on the desired client and use http.set_api_base_url()
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 (
StrapiUser,
StrapiClient,
StrapiAuthenticator
)
# Instantiate clients.
auth = StrapiAuthenticator()
user = StrapiUser(auth=auth)
client = StrapiClient(auth=auth)
# 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="some-apis", batch_size=100)
one_api_data = client.get_entry(plural_api_id="some-apis", 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)
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.1.0.tar.gz
.
File metadata
- Download URL: strapi_api_sdk-0.1.0.tar.gz
- Upload date:
- Size: 6.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.18
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5af68900bdc942d17939643a265911ae4546af9e6fa4733c663a63fc62fa3384 |
|
MD5 | 93fe6d4bd4f3ce41b4fb359d7dd85160 |
|
BLAKE2b-256 | 532e78ae3d08d7dad369db3e21da808a0498f919d784074947040e8b4bbc43dc |
File details
Details for the file strapi_api_sdk-0.1.0-py3-none-any.whl
.
File metadata
- Download URL: strapi_api_sdk-0.1.0-py3-none-any.whl
- Upload date:
- Size: 9.5 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 | 108bae0cb61358818e19a8adad02587a14d83590267ca3eb9bda765f7c6c793a |
|
MD5 | 22ec6e2d0d45fa93a803bf6c82de9650 |
|
BLAKE2b-256 | ef7f96a6ad0ddb88fddeddb220b2188959aee4f3dd6a4c457b9c72d0197c1d36 |