Python job scheduling for humans.

Related tags

schedule
Overview

schedule

https://coveralls.io/repos/dbader/schedule/badge.svg?branch=master

Python job scheduling for humans. Run Python functions (or any other callable) periodically using a friendly syntax.

  • A simple to use API for scheduling jobs, made for humans.
  • In-process scheduler for periodic jobs. No extra processes needed!
  • Very lightweight and no external dependencies.
  • Excellent test coverage.
  • Tested on Python and 3.6, 3.7, 3.8, 3.9

Usage

$ pip install schedule
import schedule
import time

def job():
    print("I'm working...")

schedule.every(10).seconds.do(job)
schedule.every(10).minutes.do(job)
schedule.every().hour.do(job)
schedule.every().day.at("10:30").do(job)
schedule.every(5).to(10).minutes.do(job)
schedule.every().monday.do(job)
schedule.every().wednesday.at("13:15").do(job)
schedule.every().minute.at(":17").do(job)

while True:
    schedule.run_pending()
    time.sleep(1)

Documentation

Schedule's documentation lives at schedule.readthedocs.io.

Meta

Daniel Bader - @dbader_org - [email protected]

Inspired by Adam Wiggins' article "Rethinking Cron" and the clockwork Ruby module.

Distributed under the MIT license. See LICENSE.txt for more information.

https://github.com/dbader/schedule

Issues
  • 'module' object has no attribute 'every'

    'module' object has no attribute 'every'

    schedule.every(10).minutes.do(job) AttributeError: 'module' object has no attribute 'every'

    My full code

    import schedule import time

    def job(): print("Helo Wolrd ")

    schedule.every(10).minutes.do(job) schedule.every().hour.do(job)

    while True: schedule.run_pending() time.sleep(1)

    question 
    opened by atuljain 17
  • โœจ Schedule roadmap + discussion

    โœจ Schedule roadmap + discussion

    Hey folks ๐Ÿ‘‹

    Progress on schedule has been kinda stale for a while now and I'd like to kick things into gear again.

    We've had a bunch of open issues and PRs that I'm triaging right now. Thanks to everyone who helped out answering usage and how-to questions, I really appreciate it! ๐Ÿ˜Š

    I've created this issue so we can discuss next steps for another schedule release in November.

    We have a bunch of PRs cooking at the moment and some of them I think would make good additions.

    However, one thing I want to avoid is growing schedule "randomly" by adding half-baked or too niche features. I think people like schedule because its interface is simple and straight-forward.

    I'm worried schedule will lose its simplicity.

    I don't think we should build another APScheduler or a replacement for Cron.

    That's definitely something that will be tough to balance and I'd love to hear your opinions on that topic as well ๐Ÿ˜ƒ .

    I also think there are some must do's that we should tackle in the next release. For me those include:

    • [x] Fix the CI build (done in #79)
    • [x] Adding Wheel support for faster installs from PyPI
    • [x] Setting up proper docs and expanding the FAQ (see #4). This will help keep questions like "how can I cancel jobs?" under control.

    Again I'd love to hear input on that, please fire away ๐Ÿ˜ƒ

    I've also toyed with the idea of setting up a Gitter chat room for schedule. I've seen this working well on other projects and I'd be happy to set it up if there's enough interest in it.

    contributor friendly 
    opened by dbader 15
  • Timezone support

    Timezone support

    Hi,

    I added timezone support using python-dateutil. Yes, it's not as minimal as before, but I think the functionality makes up for it. :-) Hope you agree.

    Ivan

    opened by imiric 15
  •  Support for parsing of string interval definitions

    Support for parsing of string interval definitions

    As a user, I want to be able to specify an interval definition as a string. This pull request implements this functionality. It parses the input string and calls the appropriate properties and functions. It slightly abuses asserts but you did not define any custom exceptions and I wanted to follow your style.

    This is how it works:

    schedule.when('every wednesday at 13:15').do(job)
    schedule.when('every 15 seconds').do(job)
    
    opened by ljanyst 13
  • More ruby-like syntax for `schedule.every`

    More ruby-like syntax for `schedule.every`

    Now to schedule new job uses the following syntax:

    schedule.every(10).minutes.do(job)
    

    Maybe the more consistent to use

    schedule.every.10.minutes.do(job)
    

    Any thoughts?

    opened by vitalk 12
  • Monthly periodicity

    Monthly periodicity

    Developed monthly periodicity functionality.

    Monthly periodicity always need to have defined 'at("DD-HH:MM:SS")' or 'at("DD-HH:MM")', where "DD" is the day of the month it should run. If "DD"=31 the periodic job will run the last day on the month.

    Other exceptions related to end of month dates or February special case are controlled, at least as far as I've been able to check.

    opened by gaguirregabiria 12
  • Add execute until functionality

    Add execute until functionality

    Add Job.until function which will execute a job until a certain time is passed.

    opened by fredthomsen 12
  • Add support for random intervals

    Add support for random intervals

    For tasks that should run at an irregular interval, this adds the following syntax:

    schedule.every(10).to(20).hours.do(job)
    

    The scheduler picks a random value in that range as the actual interval used when scheduling the next run.

    Review on Reviewable

    opened by grampajoe 12
  • Scheduled tasks are not called anymore

    Scheduled tasks are not called anymore

    Everything was fine, but on the last week scheduling stopped working. I made some testing: I have a script which defines few scheduled tasks. When running from command string this way: python myscript.py schedule work just fine. But when I run this script from another script: newprocess="nohup python myscript.py" os.system(newprocess) the scheduled tasks are not called there. in myscript.py, schedule is performed in a separate thread: `def scheduler_function(): while 1: schedule.run_pending() time.sleep(1)

    thread = Thread(target = scheduler_function, args = ()) thread.start()`

    Can you please help me with this?

    opened by madfatcat 12
  • Clear jobs by tag

    Clear jobs by tag

    The intention of this pull is to create an easy way to clear scheduled jobs in a modular environment. For doing this i added two new methods to Job class, tag() and tags(), that could be used in a way like this one

    schedule.every(10).minutes.do(job).tag('my_tag', 'my_other_tag')

    after doing this it will be possible to clear a subset of jobs by doing

    schedule.clear('my_other_tag')

    always leaving the older way possible by omitting the tag parameter. Please, tell me if you think it could be useful.

    opened by Zerrossetto 12
  • Run whole Jupyter Notebook

    Run whole Jupyter Notebook

    I am new to python coding and still learning a lot.

    How can I schedule to run my entire Jupyter notebook? I would like to schedule my code to run every weekday at a certain time.

    Here is my normal process: I have 10-20 Jupyter notebooks open. After the stock market closes for the day, I go to each notebook and click "Cell" then "Run All". I have python code in 16 different cells that analyzes different data and prints charts.

    I would like to have all these notebooks run automatically at a specific time of day.

    What is the best way to "Run All" the code in my Jupyter notebook?

    opened by turbo1618 0
  • new utc baseline for (old) schedule PR, make some datetime objs tzaware

    new utc baseline for (old) schedule PR, make some datetime objs tzaware

    Minimal rework of https://github.com/dbader/schedule/pull/256 <= that needs use-case testing by interested parties. When I used the old version of ^^ that PR I had to setup the logging to use time.gmtime to get the right (UTC) log times, however, in newer py3 versions you can use https://docs.python.org/3/library/logging.html?highlight=logging%20time#logging.Formatter.formatTime (note the note about py3.9)

    Hopefully someone finds this useful; I just don't have time right now to go back to my old project and try upgrading, etc. Enjoy!

    Setting TZ environment var in runtime may be required (also a good idea)

    schedule/test changes:

    • import timezone and set UTC default
    • adjust last_run and idle_seconds to be utc times
    • make until/cancel_after tzaware, update datetime strings
    • make should_run/run/_is_overdue use UTC times
    • make test_until_time use tzaware datetime for asserts
    • remove runtime assert, raise ScheduleError instead
    opened by sarnold 1
  • test_until_time failing since 1.1.0

    test_until_time failing since 1.1.0

    After upgrading to 1.1.0 we see the following test fail:

    ======================================================================
    FAIL: test_until_time (test_schedule.SchedulerTests)
    ----------------------------------------------------------------------
    Traceback (most recent call last):
      File "/build/schedule-1.1.0/test_schedule.py", line 317, in test_until_time
        self.assertRaises(ScheduleValueError, every().day.until, datetime.time(hour=5))
    AssertionError: ScheduleValueError not raised by until
    

    It was introduced in https://github.com/dbader/schedule/commit/1849e0165278f1cdfaf41972f73e02ecda4d09a6.

    opened by mweinelt 0
  • supports

    supports "months" and "yearsโ€ interval

    In some case, we have an scheduler in which a task may be executed every two months or two years. The current implementation does not support this kind of setting. It should be much better to support "weeks" or "years" option.

    opened by coolsnake 0
  • 1.1.1 - deadline callback

    1.1.1 - deadline callback

    Hi guys. first thanks for great library. I want to contribute small addition which is important for my application. It's callback on Job canceling.

    I need to schedule new Job after some Jobs are cancelled due to deadline. Please let me know if it's ok.

    Thanks!

    opened by stromajer 0
  • Job __repr__ throws AttributeError when job_func is None

    Job __repr__ throws AttributeError when job_func is None

    >>> s._job
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "/path/to/my/virtualenv/site-packages/schedule/__init__.py", line 284, in __repr__
        args = [repr(x) if is_repr(x) else str(x) for x in self.job_func.args]
    AttributeError: 'NoneType' object has no attribute 'args'
    

    Line 284 (and similarly line 285 for kwargs) assumes self.job_func is not None (and has the "args" attribute). I think it needs to use logic similar to line 264 (and line 265, respectively for kwargs).

    It may be helpful to extract line 264 to a reusable property:

    @property
    def _job_func_args(self):
        return () if self.job_func is None else self.job_func.args
    

    I can draft a PR if that would be helpful.

    For context, I am using schedule as a schedule-builder interface, (i.e. just Job definitions without do).

    opened by ttymck 0
  • do not hard depend on mock

    do not hard depend on mock

    I am not sure whether you need to support all versions on python 3, but in case that yes, could you please consider something like

    Index: schedule-1.1.0/test_schedule.py
    ===================================================================
    --- schedule-1.1.0.orig/test_schedule.py        2021-03-07 11:49:24.000000000 +0100
    +++ schedule-1.1.0/test_schedule.py     2021-09-08 10:48:44.066906764 +0200
    @@ -1,8 +1,11 @@
     """Unit tests for schedule.py"""
     import datetime
     import functools
    -import mock
     import unittest
    +try:
    +    import unittest.mock as mock
    +except ImportError:
    +    import mock
    
     # Silence "missing docstring", "method could be a function",
     # "class already defined", and "too many public methods" messages:
    
    
    opened by pgajdos 0
  • added delay_seconds parameter to run_pending

    added delay_seconds parameter to run_pending

    Added delay_seconds parameter to run_pending to mirror run_all. This is helpful to prevent sending too many requests too fast and can also prevent race conditions (e.g., if jobs create asynchronous tasks).

    opened by Tahlor 0
  • Is just calling 'del <scheduler instance>' suficient to clean up a schedule.Scheduler() instance?

    Is just calling 'del ' suficient to clean up a schedule.Scheduler() instance?

    Is just calling 'del ' suficient to clean up a schedule.Scheduler() instance?

    If... theScheduler=schedule.Scheduler()

    Then, cleanup is? del theScheduler theScheduler=None

    If the above is correct, theSchedule is now at zero references, and garbage collection available. right>

    opened by dachshund-digital 0
  • How would a schedule a job to be run every 5 minutes between two times, every day

    How would a schedule a job to be run every 5 minutes between two times, every day

    Hey all, Apologies if this is stupid simple - I am new to the library. I am trying to schedule a job using this library which can execute a function:

    • Every day,
    • Between 7:00 am and 9:00 am
    • Every 5 minutes In other words, I am trying to schedule those 24 instances when the job should be executed.

    PS: trying to make a logger for daily commute using the google maps api in case folks are interested.

    opened by nakulbende 2
Owner
Dan Bader
Full-stack Pythonista & Python Coach. Write Clean and Pythonic code with my free tutorials, books, and courses.
Dan Bader
A simple scheduler tool that provides desktop notifications about classes and opens their meet links in the browser automatically at the start of the class.

This application provides desktop notifications about classes and opens their meet links in browser automatically at the start of the class.

Anshit 13 Mar 23, 2021
A calendaring app for Django. It is now stable, Please feel free to use it now. Active development has been taken over by bartekgorny.

Django-schedule A calendaring/scheduling application, featuring: one-time and recurring events calendar exceptions (occurrences changed or cancelled)

Tony Hauber 796 Oct 21, 2021
A powerful workflow engine implemented in pure Python

Spiff Workflow Summary Spiff Workflow is a workflow engine implemented in pure Python. It is based on the excellent work of the Workflow Patterns init

Samuel 1k Oct 20, 2021
Crontab jobs management in Python

Plan Plan is a Python package for writing and deploying cron jobs. Plan will convert Python code to cron syntax. You can easily manage you

Shipeng Feng 1.1k Aug 22, 2021
Python-Repeated-Timer is an open-source & highly performing timer using only standard-libraries.

Python Repeated Timer Python-Repeated-Timer is an open-source & highly performing timer using only standard-libraries.

TACKHYUN JUNG 3 Sep 8, 2021
The easiest way to automate your data

Hello, world! ?? We've rebuilt data engineering for the data science era. Prefect is a new workflow management system, designed for modern infrastruct

Prefect 7.6k Oct 23, 2021