wL i*ddlmZddlmZddlmZddlmZmZmZm Z m Z ddl m Z ddl mZddlmZGdd eeZeGd d ZeGd d ZeGddZeGddZeGddZeGddZeGddZdedeede eeefde eeefde ede e eeefdeeeffdZy )!) dataclass)datetime)Enum)AnyDictListOptionalUnion) constants) SpaceHardware)parse_datetimec$eZdZdZdZdZdZdZdZy)JobStageah Enumeration of possible stage of a Job on the Hub. Value can be compared to a string: ```py assert JobStage.COMPLETED == "COMPLETED" ``` Possible values are: `COMPLETED`, `CANCELED`, `ERROR`, `DELETED`, `RUNNING`. Taken from https://github.com/huggingface/moon-landing/blob/main/server/job_types/JobInfo.ts#L61 (private url). COMPLETEDCANCELEDERRORDELETEDRUNNINGN) __name__ __module__ __qualname____doc__rrrrr_/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/huggingface_hub/_jobs_api.pyrrs" IH EGGrrc(eZdZUeed<eeed<y) JobStatusstagemessageN)rrrr__annotations__r strrrrrr-s O c]rrc,eZdZUeed<eed<eed<y)JobOwneridnametypeN)rrrr!r rrrr#r#3s G I Irr#ceZdZUdZeed<eeed<eeed<eeed<eeeed<eeeed<ee ee fed<ee ee fed <ee ed <e ed <e ed <eed <eed<ddZy)JobInfoa& Contains information about a Job. Args: id (`str`): Job ID. created_at (`datetime` or `None`): When the Job was created. docker_image (`str` or `None`): The Docker image from Docker Hub used for the Job. Can be None if space_id is present instead. space_id (`str` or `None`): The Docker image from Hugging Face Spaces used for the Job. Can be None if docker_image is present instead. command (`List[str]` or `None`): Command of the Job, e.g. `["python", "-c", "print('hello world')"]` arguments (`List[str]` or `None`): Arguments passed to the command environment (`Dict[str]` or `None`): Environment variables of the Job as a dictionary. secrets (`Dict[str]` or `None`): Secret environment variables of the Job (encrypted). flavor (`str` or `None`): Flavor for the hardware, as in Hugging Face Spaces. See [`SpaceHardware`] for possible values. E.g. `"cpu-basic"`. status: (`JobStatus` or `None`): Status of the Job, e.g. `JobStatus(stage="RUNNING", message=None)` See [`JobStage`] for possible stage values. owner: (`JobOwner` or `None`): Owner of the Job, e.g. `JobOwner(id="5e9ecfc04957053f60648a3e", name="lhoestq", type="user")` Example: ```python >>> from huggingface_hub import run_job >>> job = run_job( ... image="python:3.12", ... command=["python", "-c", "print('Hello from the cloud!')"] ... ) >>> job JobInfo(id='687fb701029421ae5549d998', created_at=datetime.datetime(2025, 7, 22, 16, 6, 25, 79000, tzinfo=datetime.timezone.utc), docker_image='python:3.12', space_id=None, command=['python', '-c', "print('Hello from the cloud!')"], arguments=[], environment={}, secrets={}, flavor='cpu-basic', status=JobStatus(stage='RUNNING', message=None), owner=JobOwner(id='5e9ecfc04957053f60648a3e', name='lhoestq', type='user'), endpoint='https://huggingface.co', url='https://huggingface.co/jobs/lhoestq/687fb701029421ae5549d998') >>> job.id '687fb701029421ae5549d998' >>> job.url 'https://huggingface.co/jobs/lhoestq/687fb701029421ae5549d998' >>> job.status.stage 'RUNNING' ``` r$ created_at docker_imagespace_idcommand arguments environmentsecretsflavorstatusownerendpointurlNc |d|_|jdxs|jd}|r t|nd|_|jdxs|jd|_|jdxs|jd|_|jdi}t |d|d |d  |_|jd |_|jd |_ |jd|_ |jd|_ |jd|_ |jdi}t|d|jd|_|jdtj |_|j"d|jj$d|j|_y)Nr$ createdAtr) dockerImager*spaceIdr+r2r%r&r$r%r&r,r-r.r/r0r1rr)rrr3z/jobs//)r$getr r)r*r+r#r2r,r-r.r/r0rr1r ENDPOINTr3r%r4)selfkwargsr)r2r1s r__init__zJobInfo.__init__~sa,ZZ ,H <0H 8B.4"JJ}5SN9S 9-GJ1G  7B't5=uV}U zz), K0!::m4zz), jj* Hb)fWovzz)?TU  :y/A/AB mm_F4::??*;1TWWIFrreturnN)rrrrr!r r rrrrr rr#r?rrrr(r(:s0d G""3-sm d3i  S ""$sCx.)) d38n %% ] ##  OM HGrr(ceZdZUeeed<eeed<eeeed<eeeed<eeeefed<eeeefed<ee ed<ee ed<eeeed <eeed <d d Z y )JobSpecr*r+r,r-r.r/r0timeouttagsarchNc |jdxs|jd|_|jdxs|jd|_|jd|_|jd|_|jd|_|jd|_|jd |_|jd |_|jd |_ |jd |_ y) Nr7r*r8r+r,r-r.r/r0rDrErF) r;r*r+r,r-r.r/r0rDrErFr=r>s rr?zJobSpec.__init__s"JJ}5SN9S 9-GJ1G zz), K0!::m4zz), jj* zz), JJv& JJv& rr@) rrrr r!r rrrr intr?rrrrCrCs3-sm d3i  S ""$sCx.)) d38n %% ] ## c] 49  3- 'rrCc*eZdZUeed<eed<ddZy) LastJobInfor$atNc >|d|_t|d|_y)Nr$rL)r$r rLrHs rr?zLastJobInfo.__init__s, .rr@)rrrr!r rr?rrrrKrKs GL/rrKc6eZdZUeeed<eeed<ddZy)ScheduledJobStatuslast_jobnext_job_run_atNc |jdxs|jd}|r tdi|nd|_|jdxs|jd}|rtt ||_yd|_y)NlastJobrP nextJobRunAtrQr)r;rKrPr r!rQ)r=r>rPrQs rr?zScheduledJobStatus.__init__sj::i(BFJJz,B3; /h/  **^4U CT8UGV~c/.BC\`rr@)rrrr rKr rr?rrrrOrOs{##h''arrOceZdZUdZeed<eeed<eed<eeed<ee ed<ee ed<e ed<e ed <d d Z y ) ScheduledJobInfoa Contains information about a Job. Args: id (`str`): Scheduled Job ID. created_at (`datetime` or `None`): When the scheduled Job was created. tags (`List[str]` or `None`): The tags of the scheduled Job. schedule (`str` or `None`): One of "@annually", "@yearly", "@monthly", "@weekly", "@daily", "@hourly", or a CRON schedule expression (e.g., '0 9 * * 1' for 9 AM every Monday). suspend (`bool` or `None`): Whether the scheduled job is suspended (paused). concurrency (`bool` or `None`): Whether multiple instances of this Job can run concurrently. status (`ScheduledJobStatus` or `None`): Status of the scheduled Job. owner: (`JobOwner` or `None`): Owner of the scheduled Job, e.g. `JobOwner(id="5e9ecfc04957053f60648a3e", name="lhoestq", type="user")` job_spec: (`JobSpec` or `None`): Specifications of the Job. Example: ```python >>> from huggingface_hub import run_job >>> scheduled_job = create_scheduled_job( ... image="python:3.12", ... command=["python", "-c", "print('Hello from the cloud!')"], ... schedule="@hourly", ... ) >>> scheduled_job.id '687fb701029421ae5549d999' >>> scheduled_job.status.next_job_run_at datetime.datetime(2025, 7, 22, 17, 6, 25, 79000, tzinfo=datetime.timezone.utc) ``` r$r)job_specschedulesuspend concurrencyr1r2Nc |d|_|jdxs|jd}|r t|nd|_t di|jdxs|jdi|_|jd|_|jd|_|jd|_|jd i}t|jd xs|jd |jd xs|jd |_ |jdi}t|d|d|d|_ y)Nr$r6r)rWjobSpecrXrYrZr1rPrSrQrT)rPrQr2r%r&r9r) r$r;r r)rCrWrXrYrZrOr1r#r2)r=r>r)r1r2s rr?zScheduledJobInfo.__init__s,ZZ ,H <0H 8B.4X6::j#9#VVZZ SU=VX  :. zz), !::m4Hb)(ZZ +Dvzz)/D"JJ'89WVZZ=W   7B't5=uV}U rr@) rrrrr!r r rrCboolrOr#r?rrrrVrVsO&P G""sm d^$  OVrrVimager,envr/r0rDrAcT|g|xsi|xstjd}|r||d<|rPddddd}t|tr+|d|vr$t t |dd||dz|d <nt ||d <d D]'}|j |s|t|d|d <|S||d <|S) N)r,r-r.r0r/<iiQ)smhdtimeoutSeconds)zhttps://huggingface.co/spaces/zhttps://hf.co/spaces/zhuggingface.co/spaces/z hf.co/spaces/r8r7)r CPU_BASIC isinstancer!rIfloat startswithlen) r^r,r_r/r0rDrWtime_units_factorsprefixs r_create_job_specrpsyb3M33  H%#$2DyI gs # 7I(I),U73B<-@CUV]^`VaCb-b)cH% &),WH% & (   F #"'F "6HY   O (#( OrN) dataclassesrrenumrtypingrrrr r huggingface_hubr huggingface_hub._space_apir huggingface_hub.utils._datetimer r!rrr#r(rCrKrOrVrIrkrprrrrwsq"33%4:sD(       UGUG UGp '' '2 // / aa a @V@V @VF& &#Y& $sCx. ! & d38n % & ] # &eCO, -& #s(^&r