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.

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.7.tar.gz (21.7 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.7-py3-none-any.whl (5.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: p4async-0.1.7.tar.gz
  • Upload date:
  • Size: 21.7 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.7.tar.gz
Algorithm Hash digest
SHA256 3ab310c3fe5a82d8605fcbff7061000c743eec86b454b38d3bb8d3d90ceedae0
MD5 231e990b69c9f41828416358f324e2c8
BLAKE2b-256 ea440d2f1665bb999719eb0b22dd90b9fbf02fa6fef5d26c1f6c345f9e524320

See more details on using hashes here.

File details

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

File metadata

  • Download URL: p4async-0.1.7-py3-none-any.whl
  • Upload date:
  • Size: 5.2 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.7-py3-none-any.whl
Algorithm Hash digest
SHA256 9305c3775791bd6bc5f5fb7f53c2b8be9dbf23e8e22a91320c16db96c267739a
MD5 5948e17618a163fa115617e8b099aa75
BLAKE2b-256 a3f2634eae21fa6000a9b05c4ca8700883438925431b2c80b887a3f3d685c1b4

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