Determine if a page may be crawled from robots.txt, robots meta tags and robot headers.
A Rust port of spatie/robots-txt.
We invest a lot of resources into creating best in class open source packages. You can support us by buying one of our paid products.
We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on our contact page. We publish all received postcards on our virtual postcard wall.
Requires Rust 1.89 or newer. You can install the package with Cargo:
cargo add spatie-robots-txtuse spatie_robots_txt::RobotsTxt;
let robots_txt = RobotsTxt::new("
User-agent: *
Disallow: /admin
Crawl-delay: 1.5
");
robots_txt.allows_for("/admin", "google"); // false
robots_txt.why_disallows("/admin", "google"); // Some(reasons), user_agent is "*"
robots_txt.crawl_delay(); // Some("1.5")
# assert!(!robots_txt.allows_for("/admin", "google"));
# assert_eq!(robots_txt.why_disallows("/admin", "google").unwrap()[0].user_agent, "*");
# assert_eq!(robots_txt.crawl_delay(), Some("1.5"));To check a page, including its meta tags and headers:
# fn main() -> Result<(), spatie_robots_txt::Error> {
use spatie_robots_txt::Robots;
let robots = Robots::create();
robots.may_index("https://www.spatie.be/nl/admin")?;
robots.may_follow_on("https://www.spatie.be/nl/admin")?;
# Ok(())
# }You can also specify a user agent:
# use spatie_robots_txt::Robots;
let robots = Robots::create().user_agent("UserAgent007");
# let _ = robots;By default, Robots will look for a robots.txt file on https://host.com/robots.txt.
Another location can be specified with with_txt_from. Use with_txt to supply a parsed RobotsTxt.
The HTTP convenience methods are blocking. The parsers work without network access and can inspect content fetched by any HTTP client. See the usage guide. An unreadable robots.txt allows crawling by default; use try_read_from to handle loading errors explicitly.
cargo test --locked --all-targets --all-features
cargo test --locked --doc --all-featuresSee all quality checks. The README and Markdown guides are tested by rustdoc, including setup on hidden # lines.
See CHANGELOG.md.
See CONTRIBUTING.md and the Rust API Guidelines.
Using an AI coding agent? Load Apollo's rust-best-practices skill when writing or reviewing code in this package.
Report vulnerabilities privately using the instructions in SECURITY.md.
The MIT License (MIT). See LICENSE.md.
