Skip to content

Educational: Minimal async pattern for synchronous Python libraries

License

Notifications You must be signed in to change notification settings

esoup/async-diff

Repository files navigation

Async-Diff: Minimal Async Pattern for Python Libraries

⚠️ UNOFFICIAL FORK - EDUCATIONAL/RESEARCH PURPOSES ONLY

This demonstrates a minimal diff pattern for adding async bulk operations to synchronous Python libraries. NOT an official release. NOT supported by original library maintainers.

Purpose

Demonstrate clean architectural patterns for:

  • Adding async/await to legacy synchronous libraries
  • Maintaining 100% backward compatibility
  • Enabling bulk/parallel operations via asyncio
  • Minimal code changes suitable for upstream consideration

Branches

  • 2.9.7 - Original baseline (upstream v2.9.7)
  • minimal-async-dns-bulk - Async implementation with idempotency

Generating the Diff

git diff 2.9.7 minimal-async-dns-bulk > async.patch

# Or compare online:
# https://github.com/esoup/async-diff/compare/2.9.7...minimal-async-dns-bulk

Pattern Overview

Core Principle

Add async versions alongside sync methods - never replace them.

# Existing sync method (unchanged API)
def update(self):
    import asyncio
    asyncio.run(self.update_async())

# New async method (opt-in)
async def update_async(self):
    # ... async implementation ...

Changes Summary

File Lines Purpose
SOLIDserverRest.py +184 Async HTTP client (aiohttp)
dns_record.py +514 Async CRUD methods
bulk_dns.py +341 Bulk operations with idempotency (NEW)
sds.py +155/-60 Async connection management
TOTAL ~860 Async + idempotency

Usage

from SOLIDserverRest.adv import SDS, DNS_record
from SOLIDserverRest.adv import bulk_update_dns_records, bulk_update_dns_records_idempotent

sds = SDS(ip_address="server", user="admin", pwd="secret")
sds.connect()

# Prepare 300 records
records = []
for record_id in range(1000, 1300):
    record = DNS_record(sds=sds, name="temp")
    record.myid = record_id
    record.refresh()
    record.set_ttl(600)
    records.append(record)

# Option 1: Update all in parallel
result = bulk_update_dns_records(records, max_concurrent=50)
print(f"✓ {result['succeeded']}/{result['total']}")

# Option 2: Idempotent updates (Ansible-friendly)
records_with_state = [(r, {'ttl': 600}) for r in records]
result = bulk_update_dns_records_idempotent(records_with_state, max_concurrent=50)
print(f"✓ Updated: {result['succeeded']}, Skipped: {result['skipped']}")

Expected Benefits

Performance: Should significantly improve bulk operation performance through parallelization

Idempotency: Ansible-friendly operations that only update when state differs

Compatibility: All existing synchronous code works unchanged

Dependencies: Only adds aiohttp

Disclaimer

UNOFFICIAL FORK - Educational/research purposes only. Not endorsed by original library authors. Use at your own risk.

Original library: https://gitlab.com/efficientip/solidserverrest


Maintained by eSoup for internal research.

About

Educational: Minimal async pattern for synchronous Python libraries

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 13

Languages