What's the correct way to use 'import requests as' in Python? or Why do some scripts use 'import requ

18 Replies, 1725 Views

Performance? Nope. *import requests as req* compiles to the same bytecode as *import requests*. It’s purely cosmetic.

I alias when:
- The name’s too long (*cough* matplotlib *cough*).
- I’m using multiple similar libs (e.g., *req* for requests, *httpx* for HTTPX).

For *requests*, I’d only alias if the script is huge. Otherwise, it’s overkill.

Messages In This Thread



Users browsing this thread: 1 Guest(s)