Censys Python API Docs | dltHub

Build a Censys-to-database pipeline in Python using dlt with AI Workbench support for Claude Code, Cursor, and Codex.

Last updated:

Censys is a platform that provides Internet-wide scanning and asset search APIs for hosts, certificates, and other internet-facing telemetry. The REST API base URL is Primary Platform API: https://api.platform.censys.io/v3/ (global endpoints under https://api.platform.censys.io/v3/). Legacy Search API base: https://search.censys.io/api/ (legacy v2/v1 endpoints remain available for some use cases). and Platform: Personal Access Token via Bearer token; Legacy Search: HTTP Basic auth with API ID and secret..

dlt is an open-source Python library that handles authentication, pagination, and schema evolution automatically. dlthub provides AI context files that enable code assistants to generate production-ready pipelines. Install with uv pip install "dlt[workspace]" and start loading Censys data in under 10 minutes.


What data can I load from Censys?

Here are some of the endpoints you can load from Censys:

ResourceEndpointMethodData selectorDescription
hosts_searchv3/global/search/queryPOST (platform unified search replaces legacy GET)results (hits array depends on query)Unified search across hosts/certificates/other records (use POST query body to target types).
hosts_viewv3/global/asset/host/{ip}GET(full object)Retrieve a single host record by IP.
certificates_viewv3/global/asset/certificate/{fingerprint}GET(full object)Retrieve a single certificate record by fingerprint.
hosts_timelinev3/global/asset/host/{ip}/timelineGETeventsHost timeline/events.
legacy_hosts_searchv2/hosts/searchGETresult.hits or result (legacy search returns paginated result object under "result" with "hits"/"results")Legacy host search (paginated preview).
legacy_certificates_searchv2/certificates/searchGET or POSTresult.hits or resultLegacy certificate search (paginated).
legacy_host_viewv2/hosts/{ip}GETresultLegacy view host (full host object under "result").
legacy_certificate_viewv2/certificates/{fp}GETresultLegacy certificate view (full certificate object under "result").
account_infov1/accountGET(object)Account info and rate limit metadata (legacy/account endpoints).
metadatav2/metadataGET(object)Dataset metadata (counts, last updated)

How do I authenticate with the Censys API?

Platform APIs require a Personal Access Token (bearer token) provided in an Authorization header (Authorization: Bearer ). Legacy Search API uses HTTP Basic auth with API ID (username) and secret (password) against https://search.censys.io/api/.

1. Get your credentials

  1. Sign in to Censys account at https://search.censys.io/account or platform dashboard. 2) For Platform API, create a Personal Access Token from the API/Access Tokens section. 3) Copy the token value and store it securely. For Legacy Search API, find your API ID and secret on the Legacy account page (My Account / API) and use them as HTTP Basic username/password.

2. Add them to .dlt/secrets.toml

[sources.censys_platform_host_dataset_source] personal_access_token = "your_personal_access_token_here"

dlt reads this automatically at runtime — never hardcode tokens in your pipeline script. For production environments, see setting up credentials with dlt for environment variable and vault-based options.


How do I set up and run the pipeline?

Set up a virtual environment and install dlt:

uv venv && source .venv/bin/activate uv pip install "dlt[workspace]"

1. Install the dlt AI Workbench:

dlt ai init --agent <your-agent> # <agent>: claude | cursor | codex

This installs project rules, a secrets management skill, appropriate ignore files, and configures the dlt MCP server for your agent. Learn more →

2. Install the rest-api-pipeline toolkit:

dlt ai toolkit rest-api-pipeline install

This loads the skills and context about dlt the agent uses to build the pipeline iteratively, efficiently, and safely. The agent uses MCP tools to inspect credentials — it never needs to read your secrets.toml directly. Learn more →

3. Start LLM-assisted coding:

Use /find-source to load data from the Censys API into DuckDB.

The rest-api-pipeline toolkit takes over from here — it reads relevant API documentation, presents you with options for which endpoints to load, and follows a structured workflow to scaffold, debug, and validate the pipeline step by step.

4. Run the pipeline:

python censys_platform_host_dataset_pipeline.py

If everything is configured correctly, you'll see output like this:

Pipeline censys_platform_host_dataset_pipeline load step completed in 0.26 seconds 1 load package(s) were loaded to destination duckdb and into dataset censys_platform_host_dataset_data The duckdb destination used duckdb:/censys_platform_host_dataset.duckdb location to store data Load package 1749667187.541553 is LOADED and contains no failed jobs

Inspect your pipeline and data:

dlt pipeline censys_platform_host_dataset_pipeline show

This opens the Pipeline Dashboard where you can verify pipeline state, load metrics, schema (tables, columns, types), and query the loaded data directly.


Python pipeline example

This example loads hosts_search and hosts_view from the Censys API into DuckDB. It mirrors the endpoint and data selector configuration from the table above:

import dlt from dlt.sources.rest_api import RESTAPIConfig, rest_api_resources @dlt.source def censys_platform_host_dataset_source(personal_access_token=dlt.secrets.value): config: RESTAPIConfig = { "client": { "base_url": "Primary Platform API: https://api.platform.censys.io/v3/ (global endpoints under https://api.platform.censys.io/v3/). Legacy Search API base: https://search.censys.io/api/ (legacy v2/v1 endpoints remain available for some use cases).", "auth": { "type": "bearer", "token": personal_access_token, }, }, "resources": [ {"name": "hosts_search", "endpoint": {"path": "global/search/query", "data_selector": "results"}}, {"name": "hosts_view", "endpoint": {"path": "global/asset/host/{ip}"}} ], } yield from rest_api_resources(config) def get_data() -> None: pipeline = dlt.pipeline( pipeline_name="censys_platform_host_dataset_pipeline", destination="duckdb", dataset_name="censys_platform_host_dataset_data", ) load_info = pipeline.run(censys_platform_host_dataset_source()) print(load_info)

To add more endpoints, append entries from the resource table to the "resources" list using the same name, path, and data_selector pattern.


How do I query the loaded data?

Once the pipeline runs, dlt creates one table per resource. You can query with Python or SQL.

Python (pandas DataFrame):

import dlt data = dlt.pipeline("censys_platform_host_dataset_pipeline").dataset() sessions_df = data.hosts_search.df() print(sessions_df.head())

SQL (DuckDB example):

SELECT * FROM censys_platform_host_dataset_data.hosts_search LIMIT 10;

In a marimo or Jupyter notebook:

import dlt data = dlt.pipeline("censys_platform_host_dataset_pipeline").dataset() data.hosts_search.df().head()

See how to explore your data in marimo Notebooks and how to query your data in Python with dataset.


What destinations can I load Censys data to?

dlt supports loading into any of these destinations — only the destination parameter changes:

DestinationExample value
DuckDB (local, default)"duckdb"
PostgreSQL"postgres"
BigQuery"bigquery"
Snowflake"snowflake"
Redshift"redshift"
Databricks"databricks"
Filesystem (S3, GCS, Azure)"filesystem"

Change the destination in dlt.pipeline(destination="snowflake") and add credentials in .dlt/secrets.toml. See the full destinations list.


Troubleshooting

Authentication failures

If you receive 401 Unauthorized: verify you are using the correct auth method for the endpoint (Platform v3 requires 'Authorization: Bearer '; Legacy endpoints require HTTP Basic with API ID / secret). Check token expiry and roles (Platform requires API Access role).

Rate limits (429)

Censys enforces rate limits per account. If you receive 429 Too Many Requests, back off and retry with exponential backoff. Check your account page for rate limit values.

Pagination and data selectors

Legacy search endpoints return an envelope object with a top-level "result" containing pagination and lists (e.g., result.hits or result). Platform unified search returns results in arrays, commonly under keys like "results" or "hits" depending on the referenced endpoint—always inspect the example response in the docs. For single-record view endpoints, the API returns the object directly (no array).

Ensure that the API key is valid to avoid 401 Unauthorized errors. Also, verify endpoint paths and parameters to avoid 404 Not Found errors.


Next steps

Continue your data engineering journey with the other toolkits of the dltHub AI Workbench:

  • data-exploration — Build custom notebooks, charts, and dashboards for deeper analysis with marimo notebooks.
  • dlthub-runtime — Deploy, schedule, and monitor your pipeline in production.
dlt ai toolkit data-exploration install dlt ai toolkit dlthub-runtime install

Was this page helpful?

Community Hub

Need more dlt context for Censys?

Request dlt skills, commands, AGENT.md files, and AI-native context.