Interact with Strapi from Python using the REST API
Project description
Strapi Client
Interact with Strapi from Python using the REST API
Install
pip install strapi-client-enhanced
Documentation
Examples
Quick start (sync version):
from strapi_client_enhanced import StrapiClient
with StrapiClient(base_url='YOUR_STRAPI_URL', token='YOUR_STRAPI_TOKEN') as client:
# await strapi.authorize(identifier='user_identifier', password='user_password') # Optional
users = client.get_documents('users', filters={'username': {'$eq': 'Pavel'}})
user_id = users.data[0]['documentId']
client.update_document('users', user_id, data={'username': 'Mark'})
Quick start (async version):
import asyncio
from strapi_client_enhanced import StrapiClientAsync
async def main():
async with StrapiClientAsync(base_url='YOUR_STRAPI_URL', token='YOUR_STRAPI_TOKEN') as client:
# await strapi.authorize(identifier='user_identifier', password='user_password') # Optional
users = await client.get_documents('users', filters={'username': {'$eq': 'Pavel'}})
user_id = users.data[0]['documentId']
await client.update_document('users', user_id, data={'username': 'Mark'})
asyncio.run(main())
Quick start with SmartDocument ORM
import asyncio
from strapi_client_enhanced import StrapiClientAsync, SmartDocument, MediaImageDocument
class User(SmartDocument):
__singular_api_id__ = 'user'
username: str
first_name: str
photo: MediaImageDocument
class Session(SmartDocument):
uid: str
user: User | None
async def main():
async with StrapiClientAsync(base_url='YOUR_STRAPI_URL', token='YOUR_STRAPI_TOKEN') as client:
# Get with relations and media by ID
user1 = await User.get_document(client, document_id='YOUR_DOCUMENT_ID')
print(user1.photo)
# List documents with automatic population
sessions = await Session.get_documents(client, sort=['created_at'])
for session in sessions:
print(session.user.photo if session.user else 'No user')
# Find one document
user1 = await User.get_first_document(client, filters={'username': 'Mark'})
if user1:
print(user1)
asyncio.run(main())
Quick start with ActiveDocument ORM (experimental)
Relations and upserts are supported in experimental mode.
import asyncio
from strapi_client_enhanced import StrapiClientAsync, ActiveDocument, DocumentField
class User(ActiveDocument):
username: str = DocumentField(unique=True)
first_name: str
class Session(ActiveDocument):
uid: str = DocumentField(unique=True)
user: User | None = DocumentField(default=None, relation=True)
async def main():
async with StrapiClientAsync(base_url='YOUR_STRAPI_URL', token='YOUR_STRAPI_TOKEN') as client:
# Update existing document
user1 = await User.get_document(client, document_id='YOUR_DOCUMENT_ID')
user1.first_name = 'Mark'
await user1.update_document(client)
# Create or update document with relation
session1 = await Session(uid='123', user=user1).upsert_document(client)
await session1.refresh(client) # populate fields from Strapi
# Create and delete document
user2 = await User(username='pavel', first_name='Pavel').create_document(client)
await user2.delete_document(client)
asyncio.run(main())
Development
Create new release
Push changes to 'main' branch following Conventional Commits.
Update documentation
docs folder is being updated automatically by GitHub Actions when source files are changed.
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file strapi_client_enhanced-1.0.1.tar.gz.
File metadata
- Download URL: strapi_client_enhanced-1.0.1.tar.gz
- Upload date:
- Size: 26.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8ebf05cd93d1f61d2b1d6e053f562ead1d37a784b4004eec2b5a07a942f4736c
|
|
| MD5 |
925a854d9bfc0d726a3bc64c9ca7bd31
|
|
| BLAKE2b-256 |
026d73a10c3e1f8527e2dbb86874ccece08e28216cf8cbff9116f704eb04ddf1
|
File details
Details for the file strapi_client_enhanced-1.0.1-py3-none-any.whl.
File metadata
- Download URL: strapi_client_enhanced-1.0.1-py3-none-any.whl
- Upload date:
- Size: 24.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b09abb5177fde19933c6ce3bd362c9fe418b12fc7a5cbc43e635c19b91f795fe
|
|
| MD5 |
957e8e2783989a9bd92026f0186b2677
|
|
| BLAKE2b-256 |
18d21df2897f6ae2fc3a0fe74b8356e15b46505c173b66a08726614dc6290bf8
|