You can create raw transaction, sign, ...etc programmatically but if you need to fetch address transactions (inputs) or broadcast the signed transaction to bitcoin network you'll need to connect to Bitcoin network.
Bitcoin-core is amazing for this purpose and if you don't want to download the whole blockchain you can alternatively use Electrum servers.
helpful commands for Bitcoin-core:
listunspent
: returns an array of unspent transaction outputs belonging to this wallet.
ListTransactions
: returns the most recent transactions that affect the wallet.
Electrum commands:
after connecting to some electrum server you should send JSON-RPC commands
listunspent
example:
{ "id": 1, "method":"blockchain.address.listunspent", "params"["1NS17iag9jJgTHD1VXjvLCEnZuQ3rJDE9L"] }
UPDATE
if you are already using Bitcoin-core, so you only need to call listunspent
to get your wallet UTXO's or provide an address to get that address UTXO's.
bitcoin-cli listunspent MIN_CONF MAX_CONF "["ADDRESS_NUMBER_ONE","ADDRESS_NUMBER_TWO"]"
If those address doesn't belong to your wallet, you should import them first.