For the same task I used a custom factor returning the sid and created a filter with it.
Actually I hoped something like that would be builtin but I couldn't find it in the single-mega-ultra-combined-help-tutorial-reference page.
Here's what I mean, the only comment is the bit you asked for, the trick is that the asset parameter to compute() holds all the sids for the pipeline securities:
from quantopian.algorithm import attach_pipeline, pipeline_output
from quantopian.pipeline import Pipeline, CustomFactor
class SidFactor(CustomFactor):
inputs = []
window_length = 1
def compute(self, today, assets, out):
out[:] = assets
def initialize(context):
sid = SidFactor()
# This is the filter you want
my_sid_filter = sid.eq(24)
pipe = Pipeline()
pipe.add(sid, 'sid')
pipe.set_screen(my_sid_filter)
attach_pipeline(pipe, 'just_my_sid')
def handle_data(context, data):
print(pipeline_output('just_my_sid'))