Skip to main content

An async extension to p4python

Project description

p4async

An async extension to p4python (PyPI, GitHub), the Python client for the Perforce (P4) version control server. This package adds awaitable wrappers around p4python operations for asyncio-based applications.

Setup

Use your favorite package manager to install the module into your project

  • pip install p4async
  • uv add p4async

Usage

from p4async import P4Async
p4a = P4Async()
await p4a.aconnect()

All relevant Perforce commands have async counterparts prefixed with a. For example: aconnect(), arun(), arun_clients(), afetch_change(), etc.

Commands are executed with a lock on a worker thread. The way this is done can be customized via subclassing.

Note: Earlier versions of p4python (prior to 2025.2) did not release the Python GIL (global interpreter lock) during connect() calls, which made aconnect() blocking. This was fixed in p4python 2025.2. For optimal async performance, use p4python 2025.2 or later.

Subclassing

P4Async provides core async wrappers, while keeping a few hooks intentionally overridable for custom behavior.

  • Override execute(self, func, *args, **kwargs) to customize how synchronous work is scheduled (for example, custom executors or instrumentation).
  • Override sync_run(self, *args, **kwargs) to wrap the underlying synchronous run() call with extra behavior. This is the primary hook around command execution.
  • Extend simple_wrap_methods and run_wrap_methods in a subclass to add additional auto-generated async wrappers in the a<method> pattern.
from p4async import P4Async


class MyP4Async(P4Async):
    async def execute(self, func, *args, **kwargs):
        # Custom scheduling/telemetry hook
        return await super().execute(func, *args, **kwargs)

    def sync_run(self, *args, **kwargs):
        # Custom behavior around the underlying P4 run()
        return super().sync_run(*args, **kwargs)

    # Example: add async wrappers for extra methods
    simple_wrap_methods = P4Async.simple_wrap_methods | {"my_custom_sync_method"}

Development

  • Use uv for dependency management and virtual environments.
  • Format and lint with ruff:
    • uvx ruff check
    • uvx ruff format --check
    • uvx ruff format
  • Run type checking for the package:
    • uv run mypy src

License

MIT

Project details


Download files

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

Source Distribution

p4async-0.1.8.tar.gz (32.3 kB view details)

Uploaded Source

Built Distribution

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

p4async-0.1.8-py3-none-any.whl (5.3 kB view details)

Uploaded Python 3

File details

Details for the file p4async-0.1.8.tar.gz.

File metadata

  • Download URL: p4async-0.1.8.tar.gz
  • Upload date:
  • Size: 32.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.6 {"installer":{"name":"uv","version":"0.10.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for p4async-0.1.8.tar.gz
Algorithm Hash digest
SHA256 799679fe166316e50a9f345690c1da4f061c6d3a07c98a334b26e18d2a154a23
MD5 6a9253eb6114ba22ffd4442342a3259c
BLAKE2b-256 7b41d3f24d05ea7a99ac2f6a71d07d094201259b49c994e7a0512f75f94a5130

See more details on using hashes here.

File details

Details for the file p4async-0.1.8-py3-none-any.whl.

File metadata

  • Download URL: p4async-0.1.8-py3-none-any.whl
  • Upload date:
  • Size: 5.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.6 {"installer":{"name":"uv","version":"0.10.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for p4async-0.1.8-py3-none-any.whl
Algorithm Hash digest
SHA256 4a0421f0db8850af039d8d6716fa71218784ea55805970e9987e58963d68fe23
MD5 aceb5e4c0c9b99066b27de47cb6ed00c
BLAKE2b-256 9afca054c41dc5c9674c5775ab044f278c6c0d7f5fdd61a0f86c79f304bd8abf

See more details on using hashes here.

Supported by

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