Skip to main content

Strapi Client

PyPI Python CI Docs

Interact with Strapi from Python using the REST API

Requirements

  • Python 3.11+
  • A running Strapi instance (public or self-hosted)

Installation

From PyPI:

pip install strapi-client

or

uv add strapi-client

Documentation

Full API Reference

Examples

Quick start (sync version):

from strapi_client 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 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 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 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.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

strapi_client-5.1.0.tar.gz (15.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

strapi_client-5.1.0-py3-none-any.whl (24.1 kB view details)

Uploaded Python 3

File details

Details for the file strapi_client-5.1.0.tar.gz.

File metadata

  • Download URL: strapi_client-5.1.0.tar.gz
  • Upload date:
  • Size: 15.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for strapi_client-5.1.0.tar.gz
Algorithm Hash digest
SHA256 480ad119d1e76799f68a36fe2bae25c92e692d06cc14f801f4b20d3df1932b21
MD5 1c671369704719d9f160c3666ff3b9bd
BLAKE2b-256 11f616f33a3635ccb2106e943539e7d0fd521de1fad8191fb1353e29052181aa

See more details on using hashes here.

Provenance

The following attestation bundles were made for strapi_client-5.1.0.tar.gz:

Publisher: build_and_release.yml on Roslovets-Inc/strapi-client

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file strapi_client-5.1.0-py3-none-any.whl.

File metadata

  • Download URL: strapi_client-5.1.0-py3-none-any.whl
  • Upload date:
  • Size: 24.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for strapi_client-5.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e36a8db50578b2b95b9f4235c4f0dc0cce890d9a21014dc28f9228c9bea2117d
MD5 21458d0e0db2743a2a7ceb1ca8c1cb1a
BLAKE2b-256 4b236bd853dc2fd1941970fc184036e73ae81cb7c25b989d0eebbda790612dc8

See more details on using hashes here.

Provenance

The following attestation bundles were made for strapi_client-5.1.0-py3-none-any.whl:

Publisher: build_and_release.yml on Roslovets-Inc/strapi-client

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

5.1.0 This release

2 files

5.0.6

2 files

5.0.5

2 files

5.0.4

2 files

5.0.3

2 files

5.0.2

2 files

5.0.1

2 files

5.0.0

2 files

4.2.1

2 files

4.2.0

2 files

4.1.6

2 files

4.1.5

2 files

4.1.4

2 files

4.1.3

2 files

4.1.2

2 files

4.1.1

2 files

4.1.0

2 files

4.0.0

2 files

3.10.1

2 files

3.10.0

2 files

3.9.0

2 files

3.8.0

2 files

3.7.4

2 files

3.7.3

2 files

3.7.2

2 files

3.7.1

2 files

3.7.0

2 files

3.6.0

2 files

3.5.1

2 files

3.5.0

2 files

3.4.0

2 files

3.3.0

2 files

3.2.1

2 files

3.2.0

2 files

3.1.0

2 files

3.0.3

2 files

3.0.2

2 files

2.9.1

2 files

2.9.0

2 files

2.8.0

2 files

2.7.0

2 files

2.6.1

2 files

2.6.0

2 files

2.5.0

2 files

2.4.0

2 files

2.3.0

2 files

2.2.0

2 files

2.1.0

2 files

2.0.0

2 files

1.2.0

2 files

1.1.1

2 files

1.1.0

2 files

1.0.0

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page