You can use the web3.py
or brownie
module of python to achieve this
web3.py
from web3 import Web3
# Connect to custom RPC network
rpc_url = 'http://localhost:8545' # Replace with your custom RPC URL
#chain_id = 1337 # Replace with your custom chain ID
web3 = Web3(Web3.HTTPProvider(rpc_url))