0xTaoDev / jupiter-python-sdk

Jupiter Python SDK is a Python library that allows you to use most of Jupiter features.
https://pypi.org/project/jupiter-python-sdk/
MIT License
146 stars 34 forks source link

circular import #8

Open Wouimbly opened 7 months ago

Wouimbly commented 7 months ago

Hi! just tried your wrapper it seems that there is circular import... ImportError: cannot import name 'TypedDict' from partially initialized module 'typing_extensions' (most likely due to a circular import)

i'm running Python 3.12.2 on win10... thanks

0xTaoDev commented 7 months ago

Hello, can you share your code where you are importing Python modules? thanks

Wouimbly commented 7 months ago

Pretty weird that the first call worked then now i'm getting the error... Here is my setup: -windows10 -python version and installation path: C:\Python312 -pip install jupiter-python-sdk -pip install asyncio -complete error stack: C:\Temp\pyjupswapper>python swapper.py Traceback (most recent call last): File "C:\Temp\pyjupswapper\swapper.py", line 5, in from solders import message File "C:\Python312\Lib\site-packages\solders__init__.py", line 25, in from . import system_program, sysvar File "C:\Python312\Lib\site-packages\solders\system_program.py", line 2, in from typing_extensions import Final, TypedDict File "C:\Python312\Lib\site-packages\typing_extensions.py", line 5, in import inspect File "C:\Python312\Lib\inspect.py", line 151, in import linecache File "C:\Python312\Lib\linecache.py", line 11, in import tokenize File "C:\Python312\Lib\tokenize.py", line 35, in from token import * File "C:\Temp\pyjupswapper\token.py", line 6, in from solana.rpc.async_api import AsyncClient File "C:\Python312\Lib\site-packages\solana\rpc\async_api.py", line 64, in from solana.rpc import types File "C:\Python312\Lib\site-packages\solana\rpc\types.py", line 5, in from typing_extensions import TypedDict ImportError: cannot import name 'TypedDict' from partially initialized module 'typing_extensions' (most likely due to a circular import) (C:\Python312\Lib\site-packages\typing_extensions.py)

command: python swapper.js

content of swapper.js: import base58 import base64 import json

from solders import message from solders.keypair import Keypair from solders.transaction import VersionedTransaction

from solana.rpc.types import TxOpts from solana.rpc.async_api import AsyncClient from solana.rpc.commitment import Processed

from jupiter_python_sdk.jupiter import Jupiter

import asyncio

private_key = Keypair.from_bytes(base58.b58decode("myKEY")) async_client = AsyncClient("myRPC") jupiter = Jupiter(async_client, private_key)

async def swap():
transaction_data = await jupiter.swap( input_mint="EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v", output_mint="So11111111111111111111111111111111111111112", amount=300_000, slippage_bps=100, )

Returns str: serialized transactions to execute the swap.

raw_transaction = VersionedTransaction.from_bytes(base64.b64decode(transaction_data))
signature = private_key.sign_message(message.to_bytes_versioned(raw_transaction.message))
signed_txn = VersionedTransaction.populate(raw_transaction.message, [signature])
opts = TxOpts(skip_preflight=False, preflight_commitment=Processed)
result = await async_client.send_raw_transaction(txn=bytes(signed_txn), opts=opts)
transaction_id = json.loads(result.to_json())['result']
print(f"Transaction sent: https://explorer.solana.com/tx/{transaction_id}")

if name == "main": asyncio.run(swap())